markdown jQuery .clone(),. append(),. appendTo()

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown jQuery .clone(),. append(),. appendTo()相关的知识,希望对你有一定的参考价值。

## jQuery `clone`

* Used to duplicate a jQuery item:

```
<div class="container">
  <div class="goodbye">
  </div>
</div>
```

* to clone `div.goodbye`: `$('.goodbye').clone();`
* While `clone` creates a **deep** copy of the item (including all children and other nested
elements), it **does not clone event handlers attached to the item!**
* To allow for this behavior, you must make `true` the parameter `withDataAndEvents`,
which is defaulted to false.

```
.clone([withDataAndEvents])
.clone(true)
```

---

## `append` **vs** `appendTo`
* Both these functions perform the same operation: **adding** something to someplace
* They differ in the order of the addition:
    * `append`'s syntax is as follows:
  
        ```
        A.append('B')
        ```
        
        * Take something that **already exists** and add it something new
    * `appendTo`'s syntax differs as follows:
        
        ```
        B.appendTo('A')
        ```
        
        * Take something **new** and add it to something that already exists
        
    

以上是关于markdown jQuery .clone(),. append(),. appendTo()的主要内容,如果未能解决你的问题,请参考以下文章

markdown 在java中复制构造函数和clone()

jQuery .clone()

jQuery 中的 clone(true) + remove() 与 detach()

JQuery UI Draggable - 如果参数传递给 clone(),则返回 clone() 的帮助函数仅克隆一次

.clone(true,true) + .remove() 的 Jquery ui 奇怪行为

jquery里怎么用clone给表格增加一行