更新时间:2023-11-03 09:55:34
$(".myClass").eq(0)
这将返回一个jQuery对象,而 .get()
返回一个DOM元素。
This returns a jQuery object, whereas .get()
returns a DOM element.
.eq()
允许你指定索引,但是如果你只想要第一个你可以使用 .first()
,或者如果你只想要最后一个你可以使用(惊喜!) .last()
。
.eq()
lets you specify the index, but if you just want the first you can use .first()
, or if you just want the last you can use (surprise!) .last()
.
我得到了一个元素数组。
不,你没有得到一个像数组一样的jQuery对象对象,而不是实际的数组。
No you don't, you get a jQuery object which is an array-like object, not an actual array.
如果您计划使用jQuery,我建议花半小时浏览所有方法的清单。
If you plan to use jQuery much I suggest spending half an hour browsing through the list of all methods.