<td>
チェックボックスがオンになっているテーブル行のみを表示するにはどうすればよいですか?
var myTable = '#testTable';
$(myTable).find('tr').has('checkbox:checked').has('td').show();
ありがとう
<td>
チェックボックスがオンになっているテーブル行のみを表示するにはどうすればよいですか?
var myTable = '#testTable';
$(myTable).find('tr').has('checkbox:checked').has('td').show();
ありがとう
これを試して:
$('#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)
これを効率的に行うには、XPathクエリで操作するノードをトラバースするという事実に依存します。つまり、後続のすべてのXPathクエリは、実際にはフィルタリングサブ検索として実行する必要があります。それを行うのは非常に簡単です。角かっこをその周りに配置すると、トリックが実行されます(およびを.
使用するためにを追加します>
)。
$('#testTable>tr[.>td>input[type=checkbox]:checked]').show();
セルだけでなく、行を表示/非表示にしたいですか?
.parent().parent()
要素に戻るために使用する必要がありますtr
。
$('#testTable>tr>td>input[type=checkbox]:checked').parent().parent().show();
$('#testTable>tr>td>input[type=checkbox]:checked').closest('tr').show();
それは...ですか:
var myTable = '#testTable';
$(myTable).find('tr').each(function(){
if($(this).find('checkbox:checked').length)
$(this).show();
});