时间:2021-07-01 10:21:17 帮助过:66人阅读
关于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>
更多range对象之selectNode等方法相关文章请关注PHP中文网!