- 被克隆元素.cloneNode(布尔类型) 包含行内属性,原生js是不包含事件,jq是包含事件的。
- 默认是false,false代表浅克隆,浅克隆不会包含内容
- 传入true,代表深克隆,深克隆会包含内容
<div class="aaa" style="width: 100px;height: 100px;background-color: black;margin-bottom: 5px;" >
<span style="color: white;">hello world</span>
</div>
<script>
let box = document.querySelector('.aaa')
box.onclick = function (){
console.log('hello world')
}
let cloneBox = box.cloneNode()
let deepCloneBox = box.cloneNode(true)
document.body.appendChild(cloneBox)
document.body.appendChild(deepCloneBox)
console.log(cloneBox,"----浅克隆")
console.log(deepCloneBox,"----深克隆")
</script>