I have a table with a bunch of little cells.
我有一张桌子上有一堆小牢房。
<table class="epic-table">
<tr>
<td class="evil">
<td class="foo">
<td class="bar">
<td class="baz">
<!-- About 2 dozen more with different classes -->
</tr>
</table>
I need a selector that will grab only the td
s with with classes foo
, bar
, or baz
. The naive solution would be to make the selector td.foo, td.bar, td.baz
, but I wonder if there isn't a better selector to do the same thing without having to repeat td
for each class.
我需要一个选择器,只使用类foo,bar或baz获取tds。天真的解决方案是使选择器td.foo,td.bar,td.baz,但我想知道是否没有更好的选择器来做同样的事情而不必为每个类重复td。
Edit for context: This is going into the filter
option for a selectable
operation on these particular cells. I am not sure if this option accepts only strings or if it also accepts jQuery objects.
编辑上下文:这将进入过滤器选项,以便对这些特定单元格进行可选操作。我不确定此选项是否只接受字符串,或者它是否也接受jQuery对象。
2 个解决方案
#1
2
Not yet a selector — that is being proposed in an upcoming standard and jQuery doesn't offer any of its own selectors, but it does provide the .filter()
method which works just as well:
还没有一个选择器 - 这是在即将推出的标准中提出的,jQuery不提供任何自己的选择器,但它确实提供了.filter()方法,它同样有效:
$('td').filter('.foo, .bar, .baz');
#2
0
You can use:
您可以使用:
$('tr').find('.foo,.bar,.baz')
#1
2
Not yet a selector — that is being proposed in an upcoming standard and jQuery doesn't offer any of its own selectors, but it does provide the .filter()
method which works just as well:
还没有一个选择器 - 这是在即将推出的标准中提出的,jQuery不提供任何自己的选择器,但它确实提供了.filter()方法,它同样有效:
$('td').filter('.foo, .bar, .baz');
#2
0
You can use:
您可以使用:
$('tr').find('.foo,.bar,.baz')