gpt4 book ai didi

jquery - :last and :last-of-type in jQuery? 和有什么区别

转载 作者:行者123 更新时间:2023-12-01 00:57:29 27 4
gpt4 key购买 nike

请看这张图片:

enter image description here

谁能解释一下其中的区别吗?

编辑

让我指出什么让我困惑。请注意:

  1. $row.is('tr.items:last') === false
  2. $row[0].id === $('tr.items:last')[0].id

这两种说法似乎互相矛盾。第一个告诉我们 $row 不是 tr.items 的最后一个。但第二个告诉我们 $row 正是 $('tr.items:last'),即 tr.items 的最后一个。

:last-of-type 选择器不会发生这样的事情。

这是怎么回事?

最佳答案

last-of-type是一个 CSS 伪类,它表示给定标签名称的最后一个同级。如果浏览器支持querySelectorAll(),它可能可以用作jQuery选择器并且您没有使用纯 jQuery 选择器;否则,它将使用 Sizzle,但 Sizzle 不支持它。请参阅this jQuery 票证。

另一方面,:last是一个 jQuery 选择器,它选择最后一个匹配的元素。

关于jquery - :last and :last-of-type in jQuery? 和有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12228625/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com