<body> <div id="main"> <div id="box">阿三大啊的</div> </div> <button onClick="clickfn(this)"> 点击</button> <script> //要复制的节点 var box = document.getElementById('box') //父节点 var main = document.getElementById('main') //自增id var id = 0 //点击事件 function clickfn() { /* html = " <div id=" box " >阿三大啊的</div>" .append(html) */ //创建节点 cloneNode(true:深拷贝) var cp_1 = box.cloneNode(true) console.log(cp_1); //手动修改id cp_1.id = `son_box-${id++}` //添加到main节点上 main.append(cp_1) } </script> </body> </html>