求問(wèn)大神們我的代碼錯(cuò)在哪里···
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無(wú)標(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ù)
? while((content.childNodes.length>0) && (content.childNodes[0].nodeType!=1))
? ? ?{?
? ? ? ? ?content.removeChild(content.childNodes[0]);
? ? ?}
}
document.write(content.childNodes[0].nodeType!=1);
</script>
<button onclick="clearText()">清除節(jié)點(diǎn)內(nèi)容</button>
</body>
</html>
2015-09-01
上段代碼只執(zhí)行了一次,刪除了文本節(jié)點(diǎn),下次執(zhí)行的時(shí)候nodeType=1了;while里的執(zhí)行不了,條件&&改成||,