課程
/前端開發(fā)
/JavaScript
/JavaScript進(jìn)階篇
當(dāng)數(shù)組寫9時(shí)候,就刪除的是Java這個(gè)元素,這個(gè)數(shù)組下標(biāo)到底是怎么一回事
2015-08-18
源自:JavaScript進(jìn)階篇 9-14
正在回答
var content=document.getElementById("content");
document.write(content.childNodes.length+"<br>");//數(shù)組長度顯示為11
document.write(content.lastChild.nodeName+"<br>");//該數(shù)組的最后一個(gè)節(jié)點(diǎn)也即為childNode[10]的節(jié)點(diǎn)為文本節(jié)點(diǎn)
document.write(content.childNodes[9].nodeName);//該數(shù)組的倒數(shù)第二個(gè)節(jié)點(diǎn)為H,元素節(jié)點(diǎn)。
之所以最后一個(gè)節(jié)點(diǎn)是文本節(jié)點(diǎn),而不是你想象中的H元素節(jié)點(diǎn),是因?yàn)楸菊虑懊嬉辉俾暶?,?jié)點(diǎn)之間的空白符,在firefox、chrome、opera、safari瀏覽器是文本節(jié)點(diǎn)。
舉報(bào)
本課程從如何插入JS代碼開始,帶您進(jìn)入網(wǎng)頁動(dòng)態(tài)交互世界
2 回答關(guān)于var x=content.removeChild(content.childNodes[1]);中的[1]的問題
1 回答for 函數(shù)中 content.removeChild(content.childNodes[0]); 為什么不是 content.removeChild(content.childNodes[i]);
1 回答for(var i=content.childNodes.length-1;i>=0;i--){ var childNode=content.childNodes[i] content.removeChild(childNode) }
2 回答for 函數(shù)中 content.removeChild(content.childNodes[0]); 為什么不是 content.removeChild(content.childNodes[i]);
1 回答for函數(shù)中為什么是 content.removeChild(content.childNodes[0]); 而不是 content.removeChild(content.childNodes[i]);
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)
2015-08-21
var content=document.getElementById("content");
document.write(content.childNodes.length+"<br>");//數(shù)組長度顯示為11
document.write(content.lastChild.nodeName+"<br>");//該數(shù)組的最后一個(gè)節(jié)點(diǎn)也即為childNode[10]的節(jié)點(diǎn)為文本節(jié)點(diǎn)
document.write(content.childNodes[9].nodeName);//該數(shù)組的倒數(shù)第二個(gè)節(jié)點(diǎn)為H,元素節(jié)點(diǎn)。
之所以最后一個(gè)節(jié)點(diǎn)是文本節(jié)點(diǎn),而不是你想象中的H元素節(jié)點(diǎn),是因?yàn)楸菊虑懊嬉辉俾暶?,?jié)點(diǎn)之間的空白符,在firefox、chrome、opera、safari瀏覽器是文本節(jié)點(diǎn)。