考虑这个片断:为什么n-child会返回?
<div>
<div class="user_photo"></div>
<h5><b>Jane Doe,</b> 01 May 2016</h5>
</div>
<div>
<div class="user_photo"></div>
<h5><b>Jane Doe,</b> 01 May 2016</h5>
</div>
当搜索jQuery('div.user_photo:nth-child(0)')
我得到:
[<div class="user_photo"></div>, <div class="user_photo"></div>]
为什么我没有拿到此数组中的第一个div?我如何获得数组的第一个元素而不添加新的类?
...因为您正在使用'用户照片'类的nth-child div。 – Scott
你试过'jQuery('div.user_photo')[0]'? – connexo
提示:''div.user_photo:n-child [1]'**应**返回'[
, ]'。这是什么意思 – slebetman