JavaScript cloneNode():克隆节点

语法:
    nodeObject.cloneNode(boolean)
参数说明:

QQ截图20161013113010.png

举例,对 id="demo" 的节点进行克隆:

<div id="demo">
    <div>点击这里进行克隆</div>
    <div>节点</div>
    <div>节点</div>
</div>
<script type="text/javascript">
document.getElementById("demo").onclick=function(){
    alert(this.cloneNode(true).children.length);
}
</script>


Weiter lernen
||
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>无标题文档</title> <div id="demo"> <div>点击这里进行克隆</div> <div>节点</div> <div>节点</div> </div> <script type="text/javascript"> document.getElementById("demo").onclick=function(){ alert(this.cloneNode(true).children.length); } </script> </head> <body> </body> </html>
einreichenCode zurücksetzen