Jquery 使用复选框选择表行 [英] Jquery Selecting Table Rows with Checkbox
问题描述
我有一张桌子
<table id="rowclick2">
<tbody>
<tr >
<td class="cb"><input type="checkbox" value="yes"></td>
<td>row 1</td>
<td>A</td>
</tr>
<tr >
<td class="cb"><input type="checkbox" value="yes" ></td>
<td>row 2</td>
<td>B</td>
</tr>
<tr>
<td class="cb"><input type="checkbox" value="yes"></td>
<td>row 3</td>
<td>C</td>
</tr>
</tbody>
</table>
我想在选中复选框的行中获取每个单元格(单击按钮时)
where I want to get each cell (when the button is clicked) in a row whose checkboxes are checked
我试过过滤
$('#test').click(function(){
$('#rowclick2 tr').filter(':has(:checkbox:checked)').each(
//get row values
);
});
很简单,但我看不到我错过了什么......
It's pretty simple yet I can't see what I am missing...
这里是jsfiddle链接...
Here is the jsfiddle link...
推荐答案
你就快到了 :)
如果您希望选中复选框的行中的所有 If you want all 例如: 更详细的示例在 JsFiddle 上. More elaborate example is on JsFiddle. 顺便说一句 BTW 这篇关于Jquery 使用复选框选择表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! s:
<td>
s in rows where the checkbox is checked:$('#rowclick2 tr').filter(':has(:checkbox:checked)').find('td');
$('#rowclick2 tr').filter(':has(:checkbox:checked)').find('td').each(function() {
// this = td element
});
.filter(':has(:checkbox:checked)')
可以写成 .has(':checkbox:checked')
如果你像我一样发现更容易阅读.
The .filter(':has(:checkbox:checked)')
can be written as .has(':checkbox:checked')
if you, like me, find that easier to read.
登录
关闭