jQuery选择除第一外的所有内容 [英] jQuery select all except first
本文介绍了jQuery选择除第一外的所有内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在jQuery中,如何使用选择器访问除元素的第一个元素以外的所有元素?因此,在下面的代码中,仅第二和第三个元素将被访问.我知道我可以手动访问它们,但是可以有任意数量的元素,所以这是不可能的.谢谢.
In jQuery how do I use a selector to access all but the first of an element? So in the following code only the second and third element would be accessed. I know I can access them manually but there could be any number of elements so thats not possible. Thanks.
<div class='test'></div>
<div class='test'></div>
<div class='test'></div>
推荐答案
$("div.test:not(:first)").hide();
或:
$("div.test:not(:eq(0))").hide();
或:
$("div.test").not(":eq(0)").hide();
或:
$("div.test:gt(0)").hide();
或:(根据@Jordan Lev的评论):
or: (as per @Jordan Lev's comment):
$("div.test").slice(1).hide();
以此类推.
请参阅:
- http://api.jquery.com/first-selector/
- http://api.jquery.com/not-selector/
- http://api.jquery.com/gt-selector/
- https://api.jquery.com/slice/
- http://api.jquery.com/first-selector/
- http://api.jquery.com/not-selector/
- http://api.jquery.com/gt-selector/
- https://api.jquery.com/slice/
这篇关于jQuery选择除第一外的所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文