Home >Web Front-end >H5 Tutorial >selectNode and other methods of range object
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>
For more articles related to selectNode and other methods of range objects, please pay attention to the PHP Chinese website!