如何仅显示包含<td>
的表格行并选中复选框?
var myTable = '#testTable';
$(myTable).find('tr').has('checkbox:checked').has('td').show();
由于
答案 0 :(得分:1)
试试这个:
$('#testTable tr td input[type=checkbox]:checked').show();
$('#testTable>tr>td>input[type=checkbox]:checked').show(); // if you want to make sure they are the direct descendants (only first descendant level)
答案 1 :(得分:1)
您想显示/隐藏行,而不仅仅是单元格吗?
需要使用.parent().parent()
退回到tr
元素。
$('#testTable>tr>td>input[type=checkbox]:checked').parent().parent().show();
答案 2 :(得分:1)
$('#testTable>tr>td>input[type=checkbox]:checked').closest('tr').show();
答案 3 :(得分:1)
有效地执行此操作取决于您遍历要在XPath查询中操作的节点的事实。这意味着所有后续的XPath查询实际上都应该作为过滤子搜索来完成。这是非常微不足道的;在它周围加上方括号可以解决问题(并且由于使用了.
而添加了>
):
$('#testTable>tr[.>td>input[type=checkbox]:checked]').show();
答案 4 :(得分:0)
是吗:
var myTable = '#testTable';
$(myTable).find('tr').each(function(){
if($(this).find('checkbox:checked').length)
$(this).show();
});