使用 jQuery '.each()' 在一组元素上的每个枚举中插入“暂停”的最佳/推荐方式是什么?
$( '.someClass' ).each( function() {
$( this ).trigger( 'click' ); //fire some request that appends a new div on the body
//wait for div to be appended to the DOM. perhaps use the pause here
//execute code once the div has been appended
});
Run Code Online (Sandbox Code Playgroud) 我怎样才能选择tbody的孩子而不是他们的后代?例如,使用以下jQuery语句:
alert( $( '.someClass tbody tr' ).length );
Run Code Online (Sandbox Code Playgroud)
使用下面的示例html将产生2的长度:
<div>
<table class='someClass'>
<tbody>
<tr>
<td>
<span>cell 1-1</span>
<table>
<tbody>
<tr class='level-2'>
<td>
<span>cell 1-2</span>
<table>
<tbody>
<tr class='level-3'>
<td><span>cell 1-3</span></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td>
<span>cell 2-1</span>
<table>
<tbody>
<tr class='level-2'>
<td>
<span>cell 2-2</span>
<table>
<tbody>
<tr class='level-3'>
<td><span>cell 2-3</span></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
Run Code Online (Sandbox Code Playgroud)