增加刪除DIV的JS寫法


 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>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM