为了账号安全,请及时绑定邮箱和手机立即绑定

为啥我在console里 getStyle (oDivArray,width)报错?

为啥我在console里 getStyle (oDivArray,width)报错?

小瓶子呀hh 2019-03-15 12:10:25
<body>     <div></div>     <div></div>     <div></div>     <div></div> <script>     var oDivArray = document.getElementsByTagName('div');     function getStyle(dom,attr){     if (window.getComputedStyle)          {return window.getComputedStyle(dom,null)[attr];}          else         {return currentStyle(dom,null);}     } </script> </body> Uncaught TypeError: Failed to execute 'getComputedStyle' on 'Window':  parameter 1 is not of type 'Element'.
查看完整描述

1 回答

?
橋本奈奈未

TA贡献436条经验 获得超108个赞

parameter 1 is not of type 'Element'

报错信息不是很明显吗?第一个参数的类型得是Element,getElementsByTagName是一个HTMLCollection

查看完整回答
反对 回复 2019-03-15
  • 1 回答
  • 0 关注
  • 712 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号