為嘛摁第一下的時(shí)候什么都刪除不掉
<!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ù)
?var j=content.childNodes.length;
? for(var i=0;i<j;i++){
? ? ? content.removeChild(content.childNodes[i]);
? }
}
</script>
<button onclick="clearText()">清除節(jié)點(diǎn)內(nèi)容</button>
2017-01-25
2017-01-17
需要刷新而已,在末尾輸出一個(gè)空白字符就好了
2017-01-04
這種方法是第一次沒(méi)反應(yīng)是因?yàn)榈玫降墓?jié)點(diǎn)數(shù)十一個(gè),刪除的都是空白節(jié)點(diǎn)。