好的我知道这应该很简单.我有一个包含数据定义和数据标签的列表.我在其中一个数据定义中有输入,因此用户可以定义定义.然后我试图获得该定义的标签名称.在jsfiddle中,警报应该提示"cycle_3" http://jsfiddle.net/M6WJp/
<dl>
<dt> cycle_1:</dt>
<dd> test </dd>
<dt> cycle_2: </dt>
<dd> test </dd>
<dt> cycle_3: </dt>
<dd>
<input class="myTest" value="test" />
</dd>
</dl>
var myErrors =$('.myTest').prev('dt').text();
alert(myErrors);
Run Code Online (Sandbox Code Playgroud) 我有这个HTML块:
<h2>heading A</h2>
<p>paragraph 1 of A</p>
<p>paragraph 2 of A</p>
<h2>heading B</h2>
<ul id="list-B">
<li>list B1</li>
<li>list B2</li>
</ul>
<p>paragraph 1 B</p>
<h2>...</h2>
..
Run Code Online (Sandbox Code Playgroud)
我需要抓住每个" h2及其内容"并将它们分组为以下内容:
<div class="news">
<h2>heading A</h2>
<div class="content">
<p>paragraph 1 of A</p>
<p>paragraph 2 of A</p>
</div>
</div>
<div class="news">
<h2>heading B</h2>
<div class="content">
<ul id="list-B">
<li>list B1</li>
<li>list B2</li>
</ul>
<p>paragraph 1 B</p>
</div>
</div>
...
Run Code Online (Sandbox Code Playgroud)
有什么建议?
我是一个live()用户,我知道不知何故live()已被弃用.我试图使用bind()在新添加的dom上运行事件,但事实并非如此.
你能告诉我怎么做bind()吗?或者还有其他方法来完成这项任务吗?
这是html:
<table>
<tr>
<td> hi there <span class="click">click me</span></td>
<tr>
<tr>
<td> hi there2 <span class="click">click me</span></td>
<tr>
<tr class="end">
<td></td>
</tr>
</table>
<button class="add_new">add new row</button>
Run Code Online (Sandbox Code Playgroud)
这是js:
var new_row = '<tr><td> hi there, new row! <span class="click">click me</span></td><tr>';
$('.add_new').click(function() {
$('.end').before(new_row);
});
$('.click').bind('click', function() {
alert('clicked');
});
Run Code Online (Sandbox Code Playgroud)
如果可能的话,我想使用本机jquery的方法而不是插件.这是我的jsfiddle http://jsfiddle.net/bondythegreat/z3uXH/