JavaScript clon...LOGIN

JavaScript cloneNode(): klon nod

Sintaks:
nodeObject.cloneNode(boolean)
Penerangan parameter:

QQ截图20161013113010.png

Contohnya, klon nod dengan 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>


bahagian seterusnya
<!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>
babperisian kursus