复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <meta charset="utf-8" /> </head> <body> <style type="text/css"> #div1 { width: 300px; height: 300px; border: 1px solid red; } </style> <input type="button" id="btnClear" value="清空" /> <div id="div1"> <button>哈哈</button> <button>哈哈</button> <button>哈哈</button> <button>哈哈</button> <button>哈哈</button> <button>哈哈</button> </div> <script type="text/javascript"> window.onload = function () { document.getElementById('btnClear').onclick = function () { var div1 = document.getElementById('div1'); while (div1.firstChild) {//firstchild属性是第一个子元素,自动向上替补,没有任何子元素时,返回undefined div1.removeChild(div1.firstChild);//清空子元素 } }; }; </script> </body> </html>
最后
以上就是时尚胡萝卜最近收集整理的关于清空层中的子元素(removeChild())的全部内容,更多相关清空层中内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复