哪里錯(cuò)了????
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<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=document.content.chiIdNodes;
document.write(j.length);
? ? var i=0 ;
? while( i < j.length)
? {
? ? ? content.removeChiId(j[i]);
? ? ? i++;
? }
}
</script>
<button onclick="clearText()">清除節(jié)點(diǎn)內(nèi)容</button>
</body>
</html>
2019-02-26
? while (content.childNodes.length > 0) {
? ? ? ? content.removeChild(content.childNodes[0]);
? ? ? }
2019-01-26
? for(var i = 0; i<content.children.length;i++){
????? content.removeChild(content.children[i]);
? }
?
2019-01-07
content已經(jīng)是通過(guò)id獲取到的節(jié)點(diǎn),var j=document.content.chiIdNodes;這里去掉document.