Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如果要选择第一个元素或 :not,有几种选择:
:not(:first)
:nth-child(1)
first()
:first-child
选择第一个“二、三和 X”元素的选项有哪些?
和
:not(the first two, three, and X?) 可以:not()通过使用JS来完成!
:not(the first two, three, and X?)
:not()
!
如果您要排除的元素连续跟随,您可以使用slice():
slice()
$(selector).slice(0,3);
JS 小提琴演示。
这将选择前三个元素,0是要开始的第一个元素的从零开始的索引,第二个3是要停止收集的元素的从零开始的索引。
0
3
第二个数字也可以是负数,如果是这样,将从返回的元素集的末尾开始计数:
$(selector).slice(1,-3);
参考:
有几种方法:
对于前 1 或 2,您可以指定使用eq:$('.class').eq(0);
eq
$('.class').eq(0);
对于有限的范围,请使用lt:$('.class').lt(3);
lt
$('.class').lt(3);
要执行 的“非” lt,请使用gt大于。
gt