代码如下,为什么这样写,清除节点时,button也会被删除??
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
</head>
<body>
<div id="content">
<h1>html</h1>
<h1>php</h1>
<h1>javascript</h1>
<h1>jquery</h1>
<h1>java</h1>
</div>
<script type="text/javascript">
function clearText() {
var content=document.getElementById("content");
// 在此完成该函数
var myh1 = content.childNodes;
for(i=0;i<myh1.length;i++){
var a = content.removeChild(myh1[i]);
}
document.write("所有节点已删除");
}
</script>
<button onclick="clearText()">清除节点内容</button>
</body>
</html>