亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

var children = root.getElementsByName('div'); 為什么有問題 ?

var children = root.getElementsByName('div'); 為什么有問題 ?

19990000 2017-09-23 22:36:17
<!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);??//執行動畫 ?var?children?=?root.getElementsByName('div');? ?for?(var?i?=?0;?i?<?children.length;?i++)?{??//循環 ????????????????//只選擇子一層div ?if(children[i].parentNode?==?root)?{???//將子元素等于根元素 ?qx(children[i]);??//那么就進行添加 ?} ????????????} ????????} ????} ????qx(one) </script> </html>
查看完整描述

1 回答

?
fdsgasgg

TA貢獻19條經驗 獲得超12個贊

getElementsByName是找name屬性的


你要用的可能是getElementsByTagName

查看完整回答
1 反對 回復 2017-09-24
  • Willsf
    Willsf
    根本原因是root的原型對象里面沒有getElementsByName屬性,只有getElementsByTagName屬性,樓主可以打印 console.dir(root.__proto__.__proto__.__proto__)展開里面只有getElementsByTagName屬性,所以報錯未定義
  • 1 回答
  • 0 關注
  • 1170 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號