點擊按鈕,執(zhí)行不了
<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ù)
??
? for(var i=0;i<content.childNodes.length;i++);
? {
? ? ?var x=content.removeChild(content.childNodes[i]);
? ? ?document.write(x);
? ? ?document.write(x.innerHTML);
? }
??
}
</script>
<button onclick="clearText()">清除節(jié)點內(nèi)容</button>
</body>
2018-08-10
for(var i=0;i<content.childNodes.length;i++);? ?for循環(huán)后面的分號去了就好,for循環(huán)不帶分號? 例:? for(XXX){ XXX}