jQuery选择器问题。 :最后一个孩子没有做我所需要的

jQuery selector problem. :last-child not doing what I need

什么样的jQuery选择器可以让我选择<tr>中具有多个<td>的最后一个<td>?注意:我试图找到一个答案,使我可以使用单个选择器或紧跟着.filter()的选择器,而不是使用.each()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<table>
  <tr>
    <td colspan="2">First Cell</td>
    <td>Second Cell</td>
  </tr>
  <tr>
    <td colspan="2">Only Cell</td>
  </tr>
  <tr>
    <td>First Cell</td>
    <td>Second Cell</td>
    <td>Third Cell</td>
  </tr>
</table>

起初,我以为td:last-child可能有用,但没有用。

alt


尝试使用此选择器:

1
td:last-child:not(:first-child)

说明:在您的情况下,最后一个孩子也是第一个孩子,因为它是父元素的唯一孩子。如果现在仅选择不是其父元素的第一个子代的最后一个子代,则将仅获得不是其父元素的唯一的子代的最后一个子代。