jQuery API 返回首页目录 | jQuery API 中英文对照版
get()
get()

取得所有匹配的(DOM)元素集合。

这是取得所有匹配元素的一种向后兼容的方式(不同于jQuery对象,而实际上两者都是元素数组)。

返回值:Array<Element>

 

示例:

选择文档中的所有图像,并返回相应的DOM元素数组。

HTML 代码:

<img src="test1.jpg"/> <img src="test2.jpg"/>

jQuery 代码:

$("img").get();

结果:

[ <img src="test1.jpg"/> <img src="test2.jpg"/> ]

 
get()

Access all matched DOM elements. This serves as a backwards-compatible way of accessing all matched elements (other than the jQuery object itself, which is, in fact, an array of elements).

It is useful if you need to operate on the DOM elements themselves instead of using built-in jQuery functions.

Return value: Array<Element>

 

Example:

Selects all images in the document and returns the DOM Elements as an Array

 $("img").get();  
Before:
 <img src="test1.jpg"/> <img src="test2.jpg"/>  
Result:
 [ <img src="test1.jpg"/> <img src="test2.jpg"/> ]  

The reverse function to obtain a jquery object from a dom element is

$(domElement)  
相关链接
asp之家 | jQuery官方网站 | jQuery中文网 | 电子书作者网站 | 电子书作者blog