1

私は次の表を持っています

<table id="table">
<tr><td>Item</td></tr>
<tr class="hide"><td>Hidden Item</td></tr>
<tr class="hide"><td>Hidden Item</td></tr>
<tr class="hide"><td>Hidden Item</td></tr>
<tr><td>Item</td></tr>
<tr class="hide"><td>Hidden Item</td></tr>
<tr class="hide"><td>Hidden Item</td></tr>
<tr><td>Item</td></tr>
<tr class="hide"><td>Hidden Item</td></tr>
<tr class="hide"><td>Hidden Item</td></tr>
<tr class="hide"><td>Hidden Item</td></tr>
<tr class="hide"><td>Hidden Item</td></tr>
<tr><td>Item</td></tr>
</table>

表示されている行をクリックすると、すぐに続くすべての非表示の行から次の表示されている行まで表示したいと考えています。非表示の行数は固定されていません。特定の要素までの行の直後を選択するにはどうすればよいですか?

4

4 に答える 4

2

. nextUntil()を使用できます- $('tr:first') を要素に置き換えます-

$('tr:first').nextUntil('tr:not(.hide)').show()
// from first tr until next one that doesn't have class=hide

おそらく toggle() を使用して次の要素を非表示/表示しますが、あなたの目標が何であるかはわかりませんが、後でやりたいことができます

$('.hide').hide();
$('tr:not(.hide)').click(function(){   
    $(this).nextUntil('tr:not(.hide)').toggle();    
});

http://jsfiddle.net/nqTJc/

</p>

于 2012-10-09T05:11:01.620 に答える
1

nextUntil を使用

$('tr').click(function(){

 $(this).nextUntil(':not("tr.hide")').show();

});​​

jsfiddle http://jsfiddle.net/K5QcA/を見つけてください

参考までに http://api.jquery.com/nextUntil/

于 2012-10-09T05:11:57.760 に答える