Jquery 在表中查找标题行元素,该元素的th单元格具有名为';校长班';

Jquery 在表中查找标题行元素,该元素的th单元格具有名为';校长班';,jquery,jquery-selectors,Jquery,Jquery Selectors,我有下面的html,我想使用jQuery获取row元素,方法是使用这个header row元素中的所有th单元格都有一个固定的“headerClass”类 获取这样一行的jQuery选择器是什么? <tr> <th class="headerClass">Header1</th> <th class="headerClass">Header2</th> <th class="headerClass">Header

我有下面的html,我想使用jQuery获取row元素,方法是使用这个header row元素中的所有th单元格都有一个固定的“headerClass”类

获取这样一行的jQuery选择器是什么?

<tr>
  <th class="headerClass">Header1</th>
  <th class="headerClass">Header2</th>
  <th class="headerClass">Header3</th>
  <th class="headerClass">Header4</th>
  <th class="headerClass">Header5</th>
</tr>

校长1
校长2
校长3
校长4
校长5

为确保仅当行的所有单元格都具有该类时(即其所有单元格都没有该类),才能获取该行,您需要使用
:not()
:has()
的组合:

如果上述选择器符号过于混乱,则以下操作相同:

$('tr').not(':has(th:not(.headerClass))')

A th不能包含td元素(除非那些td位于它们自己的内部表中)。th是一个单元格,不是一行。您可能想要一个只有th元素的tr的thead。谢谢。我已经纠正了这个问题。哇,太好了。我永远不会想到这一点。谢谢你的精彩回答。
$('tr').not(':has(th:not(.headerClass))')