jQuery的是一个数组? [英] Is jQuery an Array?
问题描述
我刚刚进入jQuery和我有理解的问题是什么。如何使用一个jQuery对象数组索引风格jQuery的,但不会是一个数组?这是一个JavaScript的事情吗?
< UL ID =myUL>
<立GT;< /李>
<李ID =第二>< /李>
<立GT;< /李>
< / UL>VAR jqueryObject = $(#myUL>李);
警报(jqueryObject [1] .attributes.getNamedItem(ID)值。);如果(jqueryObject的instanceof阵列){
警报('值阵!);
}其他{
警报('不是一个数组'); //这是弹出
}
一个jQuery的收集与编号像数组索引(和其他一些属性和方法)的属性,各持有匹配的元素之一的对象。它也给出了length属性来告诉你选择多少个元素相匹配。请参见 http://api.jquery.com/Types/#jQuery
此外,是的,这部分是一个JavaScript的事情 - JS让你用点符号或用方括号标记访问对象的属性。
。I'm just getting into jQuery and I am having problems understanding what it is. How can I use array style indexing on a jQuery object but jQuery not be an array? Is this a javascript thing?
<ul id="myUL">
<li></li>
<li id="second"></li>
<li></li>
</ul>
var jqueryObject = $("#myUL > li");
alert(jqueryObject[1].attributes.getNamedItem("id").value);
if (jqueryObject instanceof Array) {
alert('value is Array!');
} else {
alert('Not an array');//this is what pops up
}
A jQuery collection is an Object with properties numbered like Array indexes (and some other properties and methods), each holding one of the matched elements. It is also given a length property to tell you how many elements the selector matched. See http://api.jquery.com/Types/#jQuery
Also, yes, it is partly a JavaScript thing--JS lets you access an object's properties with dot notation or with square-bracket notation.
这篇关于jQuery的是一个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!