Home > Web Front-end > H5 Tutorial > body text

clone method of range object

高洛峰
Release: 2017-02-09 14:37:31
Original
1389 people have browsed it

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>
Copy after login
<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>
Copy after login

For more articles related to the clone method of range object, please pay attention to the PHP Chinese website!

Related labels:
h5
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!