请教jquery怎么选择tr下的n个tr
请问jquery如何选择tr下的n个tr?
如在做全选功能,用的是表格。
例子
<tr class='level_1'><input type='check' value='选定子集' /></tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_1'><input type='check' value='选定子集' /></tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_1'><input type='check' value='选定子集' /></tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
我想点击“level_1”下面的checkbox后,把level_1下面的level_2中的checkbox全选,请问该如何实现。就是两个 level_1中间的level_2 中的checkbox全部选中。
------解决方案--------------------
如在做全选功能,用的是表格。
例子
<tr class='level_1'><input type='check' value='选定子集' /></tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_1'><input type='check' value='选定子集' /></tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_1'><input type='check' value='选定子集' /></tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
<tr class='level_2'><input type='check' value='子集1' /><input type='radio' value='子集2' />....</tr>
我想点击“level_1”下面的checkbox后,把level_1下面的level_2中的checkbox全选,请问该如何实现。就是两个 level_1中间的level_2 中的checkbox全部选中。
------解决方案--------------------
$(function() {
$('.level_1').click(function() {
var t = $(this).find(':checkbox').prop('checked');
var el = $(this).next();
while($(el).attr('class') == 'level_2') {
el.find(':checkbox').prop('checked', t);
el = el.next();
}
});
});