jQuery选择器是否返回HTML元素或jQuery对象的数组?
Q
中存储了什么?
What is stored in Q
?
Q = $('div');
Q2 = document.getElementsByTagName('div');
我可以使用Q[index]
访问每个HTML元素,类似于Q2[index]
;这使得Q
似乎是HTML元素数组.
I can access each HTML element by using Q[index]
, similar to Q2[index]
; which makes it seem like Q
is an array of HTML Elements.
另一方面,我可以做Q.filter()
,但是我不能做Q2.filter()
;这使得Q
似乎是jQuery对象的数组.
On the other hand, I can do Q.filter()
, but I cannot do Q2.filter()
; which makes it seem like Q
is an array of jQuery objects.
还是两者都存在,其中Q
是一个包含一堆HTML元素的jQuery对象?如果是这种情况,console.log()
不会将Q
检测为内部包含对象集合的对象吗? http://jsfiddle.net/rkw79/3s7tw/这个小提琴表明它们是相同的.
Or is it both, where Q
is a jQuery object that holds a bunch of HTML elements? If this was the case, wouldn't console.log()
detect Q
as an object with a collection of objects inside it? This fiddle, http://jsfiddle.net/rkw79/3s7tw/, shows that they are the same.
注意:我知道Q.eq(index)
将返回可以使用jQuery方法的对象.我只是想知道Q
Note: I am aware that Q.eq(index)
will return an object that can use jQuery methods. I'm just wondering what exactly is Q
结果是一个jQuery
对象,其行为类似于使用[]
的HTMLElements
数组和jQuery
的array
数组>使用eq(index)
;
The result is a jQuery
object that behaves like both an array of HTMLElements
which you get using []
and an array
of jQuery
objects which you get using eq(index)
;