jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
clone
clone(deep)

克隆匹配的DOM元素并且选中这些克隆的副本。 在想把DOM文档中元素的副本添加到其他位置时这个函数非常有用。

返回值:jQuery

参数:

  • deep (Boolean): (可选)如果除了元素本身不想克隆其任何后代节点设置为false
 
示例:

克隆所有b元素(并选中这些克隆的副本),然后将它们前置到所有段落中。

$("b").clone().prependTo("p"); 

HTML 代码:

<b>Hello   <span>world</span></b><p>, how are you?</p>

结果:

<b>Hello   <span>world</span></b><p>Hello   <span>world</span></b>, how are you?</p>
 

clone( deep )

Clone matched DOM Elements and select the clones.

This is useful for moving copies of the elements to another location in the DOM.

Return value: jQuery
Parameters:

  • deep (Boolean): (Optional) Set to false if you don't want to clone all descendant nodes, in addition to the element itself.
 

Example:

Clones all b elements (and selects the clones) and prepends them to all paragraphs.

 $("b").clone().prependTo("p");  
Before:
 <b>Hello</b><p>, how are you?</p>  
Result:
 <b>Hello</b><p><b>Hello</b>, how are you?</p>