childNodes存在兼容性問題滩褥,children沒有兼容性問題,用法基本一樣炫加。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>1.2 children</title>
<script>
window.onload = function () {
/* body... */
var oUl = document.getElementById('ul1');
/*
元素.children :只讀屬性 子節(jié)點列表集合
標(biāo)準(zhǔn)或非標(biāo)準(zhǔn)下都只包含元素節(jié)點
*/
for(var i=0;i<oUl.children.length;i++){
oUl.children[i].style.background = 'red';
}
}
</script>
</head>
<body>
<ul id="ul1">
<li>111</li>
<li>222</li>
<li>333</li>
<li>444</li>
</ul>
</body>
</html>
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者