Home > Article > Web Front-end > clone method of range object
clone: Clone of range object;
<body> <p id="p">这是一段文字</p> <button onclick="btn()">克隆</button> <script> function btn() { var p=document.getElementById("p"); var rangeObj=document.createRange(); rangeObj.selectNodeContents(p) var clone=rangeObj.cloneRange(); alert(clone.toString()); } </script> </body>
<body> <div id="div">这是要克隆的文字内容<br/></div> <button onclick="btn()">克隆</button> <script> function btn() { var div=document.getElementById("div"); var rangeObj=document.createRange(); rangeObj.selectNodeContents(div); var clone=rangeObj.cloneContents(); //appendChild() 方法向节点添加最后一个子节点。 div.appendChild(clone); } </script> </body>
For more articles related to the clone method of range object, please pay attention to the PHP Chinese website!