按索引选择元素(同一类的多个元素) [英] Select element by index (multiple elements of same class)
本文介绍了按索引选择元素(同一类的多个元素)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法用Javascript或jQuery按索引选择元素?例如:
Is there a way to select a element by index with Javascript or jQuery? For instance:
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
在jQuery下我可以得到4的长度,现在有办法选择然后操纵一个基于索引号的div.item元素?
Under jQuery I could get the length as 4, now is there a way to select and then manipulate a element of "div.item" based on its index number?
推荐答案
$ (div.item)。eq(0)
将为您提供第一个元素。
$("div.item").eq(0)
will give you the first element.
这篇关于按索引选择元素(同一类的多个元素)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文