节点的添加与删除

 1 <!DOCTYPE html>
 2 <html>
 3     <head>
 4         <meta charset="UTF-8">
 5         <title></title>
 6     </head>
 7     
 8     <body>
 9         <button onclick="addFun()">添加节点</button>
10         <button onclick="removeFun()">删除节点</button>
11         <div id="result"></div>
12     </body>
13     
14     <script type="text/javascript">
15         function $ (id){
16             return document.getElementById(id);
17         }
18         function addFun(){
19             var box=document.createElement('div');
20             box.innerHTML="title";
21             $('result').appendChild(box);
22         }
23         function removeFun(){
24             var x=$('result');
25             //    从最后个节点删除
26             x.removeChild(x.lastChild);
27         }
28     </script>
29 </html>
懂的越多,不会的也就越多,知识之路是不断进取的。。。
原文地址:https://www.cnblogs.com/chenrenshui/p/6016687.html