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

把与表达式匹配的元素添加到jQuery对象中。这个函数可以用于连接分别与两个表达式匹配的元素结果集。

返回值:jQuery

参数:

  • expr (String): 用于匹配相加结果元素的表达式
 

示例:

$("p").add("span")

HTML 代码:

<p>Hello</p><p><span>Hello Again</span></p>

结果:

[ <p>Hello</p>, <p><span>Hello Again</span></p>, <span>Hello Again</span> ]

 
add( expr )

Adds more elements, matched by the given expression, to the set of matched elements.

Return value: jQuery
Parameters:

  • expr (String): An expression whose matched elements are added
 

Example:

Compare the above result to the result of $('p'), which would just result in [ <p>Hello</p> ]. Using add(), matched elements of $('span') are simply added to the returned jQuery-object.

 $("p").add("span")  
Before:
 (HTML) <p>Hello</p><span>Hello Again</span>  

Result:

 (jQuery object matching 2 elements) [ <p>Hello</p>, <span>Hello Again</span> ]  


 

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