jQuery-访问数组中的元素 [英] jQuery - Access elements in array
本文介绍了jQuery-访问数组中的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要能够从数组中获取元素的宽度
I need to be able to get the width of elements from an array
HTML
<div id="container">
<ul>
<li id="one">--------</li><br />
<li id="two">----------------</li><br />
<li id="three">-------</li><br />
</ul>
</div>
JS
我知道我可以像这样访问各个宽度
I know i can access the individual width's like this
$('#one').width();
但是在一个数组中
var $array = $("#container li");
如何通过元素的索引访问元素的特定宽度
How do i access a specific width of the element by its index
例如
$array[2].width(); //which causes error
推荐答案
使用 eq :
$('#container li').eq(i)
这篇关于jQuery-访问数组中的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文