Home > Web Front-end > H5 Tutorial > clone method of range object

clone method of range object

高洛峰
Release: 2017-02-09 14:37:31
Original
1510 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
Latest Issues
Personal Alipay uses H5 to enable payment
From 1970-01-01 08:00:00
0
0
0
Can H5 video tag set brightness?
From 1970-01-01 08:00:00
0
0
0
html5 - How to use weex H5 terminal and run it?
From 1970-01-01 08:00:00
0
0
0
javascript - H5 mobile development
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template