所以我有一个非常愚蠢的问题。我正在为官方游戏网站进行设计。他告诉我会有很多截图。我做了一个设计,一切都很好,但确实有很多,所以我想通过 jQuery 在移动版本(px < 640px)中关闭它们,然后创建按钮来显示它们。我知道 Internet 上有很多说明,但它们根本没有与我的标记进行比较,实际上我希望它具有与我想的完全相同的结构。 所以我想要的是找到我的图像 block 的每个 child 的第 n 个子编号,以及第 n 个子编号大于 4 的每个 block 到 .hide()。感谢您的帮助!
<div class="images-block">
<div class="image-sq">
<p>⇕ Expand</p>
</div><div class="image-sq">
<p>⇕ Expand</p>
</div><div class="image-sq">
<p>⇕ Expand</p>
</div><div class="image-sq">
<p>⇕ Expand</p>
</div><div class="image-sq">
<p>⇕ Expand</p>
</div><div class="image-sq">
<p>⇕ Expand </p>
</div>
</div>
最佳答案
使用 gt
选择器。
$(".images-block .image-sq:gt(3)").hide();
https://api.jquery.com/gt-selector/
Select all elements at an index greater than index within the matched set.
关于javascript - 如何选择 div 的每个 child 并获得第 n 个数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33442961/