Home > Web Front-end > H5 Tutorial > selectNode and other methods of range object

selectNode and other methods of range object

高洛峰
Release: 2017-02-09 14:47:04
Original
2801 people have browsed it

selectNode and other methods of range objects

关于range对象的selectNodeContents、selectNode、deleteContents方法
示例代码如下:
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <div id="div" style="background-color:rosybrown;width:500px;height:200px;">这里有文字</div>
    <input type="button" onclick="deleteContent(true)" value="删除内容">
    <input type="button" onclick="deleteContent(false)" value="删除元素">
    <script>
        function deleteContent(test) {
            var div=document.getElementById("div");
            var range=document.createRange();
            if (test){
                range.selectNodeContents(div);
                range.deleteContents();
            }else{
                range.selectNode(div);
                range.deleteContents();
            }
        }
    </script>
</body>
</html>
Copy after login

For more articles related to selectNode and other methods of range objects, please pay attention to the PHP Chinese website!

Related labels:
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