<!DOCTYPE?HTML>
<html>
<head>
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8">
<title>無標(biāo)題文檔</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");
??//?在此完成該函數(shù)
??var?x=content.removeChild(content.childNodes[0]);
??x=null;
}
</script>
<button?onclick="clearText()">清除節(jié)點(diǎn)內(nèi)容</button>
</body>
</html>
2016-09-23
在谷歌或火狐下標(biāo)簽后面的空白算一個(gè)Textnode,所以你每次需要點(diǎn)擊兩次才能清楚,第一次清楚空白,第二次才是h1標(biāo)簽。ie8及以下版本的空白就不算一個(gè)Textnode。
2016-09-23
如何更改那?
2016-09-23
原來是游覽器