<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <body> <div id="div" style="background: palevioletred; 200px;height: 200px;">选中内容删除内容</div> <form> <input type="button" value="删除选中内容" onclick="selecion(true)"> <input type="button" value="删除选中元素" onclick="selecion(false)"> </form> <script> function selecion(content){ var div=document.getElementById("div"); var rangeObj=document.createRange(); if(content){ rangeObj.selectNodeContents(div); rangeObj.deleteContents(); }else{ rangeObj.selectNode(div); rangeObj.deleteContents(); } } </script> </body> </html>