課程
/前端開發(fā)
/JavaScript
/JavaScript進(jìn)階篇
為何i等于1是才有效果。0時(shí)無效果
2017-02-05
源自:JavaScript進(jìn)階篇 9-14
正在回答
而且下標(biāo)從0開始,到mylen-1
<!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ù) ??document.write(content.childNodes.length+"</br>"); ??var?mylen=content.childNodes.length; ??//隨著你刪除節(jié)點(diǎn),長度會(huì)變化,所以要事先保存在變量里面 ??for(var?i=0;i<mylen;i++) ??{ ??????var?a=content.childNodes[i]; ??????content.removeChild(a); ??} ?? } </script> <button?onclick="clearText()">清除節(jié)點(diǎn)內(nèi)容</button> </body> </html>
舉報(bào)
本課程從如何插入JS代碼開始,帶您進(jìn)入網(wǎng)頁動(dòng)態(tài)交互世界
2 回答for循環(huán)
3 回答for 循環(huán)
1 回答for循環(huán)
3 回答for循環(huán)
1 回答while循環(huán)和for循環(huán)的區(qū)別
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2017-02-05
而且下標(biāo)從0開始,到mylen-1
2017-02-05