for函數(shù)中為什么是 content.removeChild(content.childNodes[0]); 而不是 content.removeChild(content.childNodes[i]);
function?clearText()?{ ??var?content=document.getElementById("content"); ??var?nole=content.childNodes.length; ??for(var?i=0;i<nole;i++) ??{ ??????content.removeChild(content.childNodes[0]);??? ??} ??//?在此完成該函數(shù) }
2015-07-13
看for循環(huán)順序是怎么樣的,如果是從0開始循環(huán),你每次刪除第一個,后面的就向前推,于是又有了第一個,有n個元素,就刪除n次就好了。理解了嗎?