当前位置:   article > 正文

常见报错——Uncaught TypeError: document.getElementsByClassName(...).addEventListener is not a function_uncaught typeerror: $(...).addeventlistener is not

uncaught typeerror: $(...).addeventlistener is not a function
  • 在进行原生的前端开发的时候遇到的问题:
    Uncaught TypeError: document.getElementsByClassName(...).addEventListener is not a function......
    
    • 1
  • 原因:
    1. 选择器没有正确选择元素对象
      document.getElementsByClassName(…)捕捉到的是该类名元素的数组
  • 解决方法
    1. document.getElementsByClassName(…)[0].addEventListener…
      通过 [0] 选定需要的元素对象
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/486664
推荐阅读
相关标签
  

闽ICP备14008679号