码迷,mamicode.com
首页 > Web开发 > 详细

原生js怎么删除一个 div

时间:2017-12-12 17:29:45      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:strong   view   w3c   ref   javascrip   alt   main   charset   tee   

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
  2. <html xmlns="http://www.w3.org/1999/xhtml">  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />  
  5. <title>增加删除DIV的JS写法</title>  
  6. </head>  
  7.   
  8. <body>  
  9. <div id="main">  
  10.     <div id="box">111</div>  
  11.     <div class="box2">222</div>  
  12. </div>  
  13. <script type="text/javascript">  
  14. var box = document.getElementById("box");  
  15. var main = document.getElementById("main");  
  16. var newMask = document.createElement("div");  
  17. newMask.id ="newMask";  
  18. main.appendChild(newMask);   
  19. if(box){  
  20.     box.parentNode.removeChild(box);  
  21. }  
  22. else{  
  23.     alert("没有这个div");  
  24. }  
  25. </script>  
  26. </body>  
  27. </html>  

 

 

[html] view plain copy
 
  1. <div id="main">  
  2.     <div id="box">111</div>  
  3.     <div class="box2">222</div>  
  4. </div>  
  5. <script type="text/javascript">  
  6. var box = document.getElementById("box");  
  7. box.parentNode.removeChild(box);  
  8. </script>  

原生js怎么删除一个 div

标签:strong   view   w3c   ref   javascrip   alt   main   charset   tee   

原文地址:http://www.cnblogs.com/kongxc/p/8028339.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!