如何获取具有特定子项的项目列表? [英] How to get the list of items that have a particular subitem?
本文介绍了如何获取具有特定子项的项目列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个表格,每行以复选框开头,我想得到包含一个复选框的所有TR,并且检查。
I have table where each row starts with a "checkbox", I'd like to get all the TR that contains a checkbox and it is check.
Something像这样:
Something like this:
$('#' + tableId + ' > tbody > tr:contains(td > input[type=checkbox]:checked').each(function (i, item) {
alert('delete ' + $(item).data('row-id'));
});
该代码不起作用,它会卡住。可能是因为contains选择器仅用于文本。我怎么能这样做?
That code doesn't work, it gets stuck. Probably because the "contains" selector is only for text. How could I do it?
问候。
推荐答案
使用jQuery的有:
$('#' + tableId + ' > tbody > tr:has(td > input[type=checkbox]:checked)').each(function (i, item) {
alert('delete ' + $(item).data('row-id'));
});
性能(参见jQuery API文档),请使用:
For better performance (see the jQuery API docs), use this:
$('#' + tableId + ' > tbody > tr')
.filter(':has(td > input:checkbox:checked)').each(function (i, item) {
alert('delete ' + $(item).data('row-id'));
});
由于有
查询无法运行 querySelectorAll()
,不需要使用 [type = checkbox]
。
Since the has
query cannot be run through querySelectorAll()
, there's no need to use [type=checkbox]
.
这篇关于如何获取具有特定子项的项目列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文