jQuery 如何使用jquery检查TR是否包含具有特定CSS类的TD?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10360450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to check if a TR contains a TD with a specific CSS class with jquery?
提问by Rolando
I know you can use .find
to find td:contains('text')
, but if I have a tr with say, 3 td's, and one of the td's mighthave class="specialclass someotherclass"
(may potentially have other classes in addition to special class), how do I use jquery to check if a TR contains a TD of specialclass
?
我知道你可以.find
用来 find td:contains('text')
,但是如果我有一个 tr 说,3 个 td,并且其中一个 td可能有class="specialclass someotherclass"
(除了特殊类之外可能还有其他类),我如何使用 jquery 来检查一个 TR包含specialclass
?
回答by BoltClock
To select any tr
that has a td.specialclass
:
要选择任何tr
具有td.specialclass
:
$('tr:has(td.specialclass)')
Or if you have a tr
(represented by this
) and you simply want to check if it has such a td
:
或者,如果您有一个tr
(由 表示this
)并且您只想检查它是否有这样的td
:
if ($(this).find('td.specialclass').length)
回答by dtbarne
if ($("tr").has("td.specialclass").length > 0) {
// has specialclass
}
or
或者
if ($("tr:has(td.specialclass)").length > 0) {
// has specialclass
}