最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為什么這樣寫結(jié)果會(huì)出錯(cuò)??

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標(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ù)
? for(var i=0;i<content.childNodes.length;i++)
? {
????? if(content.removeChild(content.childNodes[i])!=null)
????? {
????????? document.write(content.childNodes[i].innerHTML+"節(jié)點(diǎn)清除成功<br>");
??????? ? content.childNodes[i].innerHTML = null;
????? }
?? else
????? {
????????? document.write(content.childNodes[i].innerHTML+"節(jié)點(diǎn)清除失敗"+"<br>");
????? }
? }
}
</script>

<button onclick="clearText()">清除節(jié)點(diǎn)內(nèi)容</button>

</body>
</html>



正在回答

2 回答

for(var?i=0;i<content.childNodes.length;i++){let?willRemoveContent?=?content.childNodes[i].innerHTML;if(content.removeChild(content.childNodes[i])!=null){document.write(willRemoveContent?+"節(jié)點(diǎn)清除成功<br>");//?content.childNodes[i].innerHTML?=?null;}else{document.write(willRemoveContent+"節(jié)點(diǎn)清除失敗"+"<br>");
if(content.removeChild(content.childNodes[i])!=null)

的時(shí)候已經(jīng)removeChild了 child,然后下面又去獲取 child 的 innerHTML?

content.childNodes[i].innerHTML+"節(jié)點(diǎn)清除成功<br>"


0 回復(fù) 有任何疑惑可以回復(fù)我~
?//?這里已經(jīng)將childNodes[i]移除了
?if(content.removeChild(content.childNodes[i])!=null)
??????{
??????????//?這里再去讀取content.childNodes[i]?不合理
??????????document.write(content.childNodes[i].innerHTML+"節(jié)點(diǎn)清除成功<br>");
??????????content.childNodes[i].innerHTML?=?null;
??????}
???else
??????{
??????????document.write(content.childNodes[i].innerHTML+"節(jié)點(diǎn)清除失敗"+"<br>");
??????}

試試這個(gè):

let?willRemoveContent?=?content.childNodes[i].innerHTML;
if(content.removeChild(content.childNodes[i])!=null)
{
????document.write(willRemoveContent?+"節(jié)點(diǎn)清除成功<br>");
}
else
{
????document.write(willRemoveContent+"節(jié)點(diǎn)清除失敗"+"<br>"
);

吐槽一下慕課做的排版真是麻煩

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么這樣寫結(jié)果會(huì)出錯(cuò)??

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)