我用的360,不是應該算文字空白節點嗎?我試了下,childNodes的長度是11啊,那應該是刪除13579?。吭趺磿沁B續的?<!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");? // 在此完成該函數? for(var i=0;i<content.childNodes.length;i++)? {? ? ? if(content.childNodes[i].nodeType!=3)? ? ? {? ? ? ? ? var x=content.removeChild(content.childNodes[i]);? ? ? ? ? document.write("刪除"+i+":"+x.innerHTML+"<br/>");? ? ? ? ?? ? ? }? }}</script><button onclick="clearText()">清除節點內容</button></body></html>
添加回答
舉報
0/150
提交
取消