我想了解jQuery对象和DOM元素之间的关系
jQuery对象是包含DOM元素的类似于数组的对象。jQuery对象可以包含多个DOM元素,具体取决于您使用的选择器。
还有什么方法可以对jQuery对象和DOM元素进行操作?一个jQuery对象可以代表多个DOM元素吗?
jQuery函数(完整列表在网站上)在jQuery对象上起作用,而不在DOM元素上起作用。您可以使用
.get()或直接在所需索引处访问元素来访问jQuery函数中的DOM元素:
$("selector")[0] // Accesses the first DOM element in this jQuery object$("selector").get(0) // Equivalent to the pre above$("selector").get() // Retrieve a true array of DOM elements matched by this selector换句话说,以下内容将为您带来相同的结果:
<div id="foo"></div>alert($("#foo")[0]);alert($("#foo").get(0));alert(document.getElementById("foo"));有关jQuery对象的更多信息,请参见文档。另请参阅有关的文档
.get()



