<!DOCTYPE?html>
<html?lang="en">
<head>
????<meta?charset="UTF-8">
????<title>Title</title>
????<style>
????????div{
????????????width:50px;
????????????height:50px;
????????????border:1px?solid?#000000;
????????}
????</style>
</head>
<body>
????<div?class="one">
????????1
????????<div?class="two"?style="margin-left:?50px;">
????????????2
????????????<div?class="three"??style="margin-left:?50px;">
????????????????3
????????????????<div?class="four"??style="margin-left:?50px;">4</div>
????????????</div>
????????</div>
????????<div?class="one">1</div>
????</div>
</body>
<script>
????var?one=document.getElementsByClassName("one")[0];
????var?i;
????function?visit(node){
????????i?+=400;
????????node.style.backgroundColor="#fff";
????????setTimeout(function(){
????????????node.style.backgroundColor="#0f0";
????????},i)
????}
????function?qx(root){
????????if?(root)?{??//如果根元素村子
?visit(root);??//執(zhí)行動(dòng)畫
?var?children?=?root.getElementsByName('div');?
?for?(var?i?=?0;?i?<?children.length;?i++)?{??//循環(huán)
????????????????//只選擇子一層div
?if(children[i].parentNode?==?root)?{???//將子元素等于根元素
?qx(children[i]);??//那么就進(jìn)行添加
?}
????????????}
????????}
????}
????qx(one)
</script>
</html>
var children = root.getElementsByName('div'); 為什么有問題 ?
19990000
2017-09-23 22:36:17