ERROR Cannot read properties of undefined (reading 'addEventListener')
时间: 2023-08-25 12:15:52 浏览: 1770
addEventListener 的用法示例介绍
5星 · 资源好评率100%
这个错误的原因是无法读取undefined对象的addEventListener属性。根据提供的代码,可能的原因是document.querySelector(".tab .active")返回了undefined,因此无法访问其classList属性。请确保在代码中正确使用了选择器,并且确保选择器匹配到了正确的元素。此外,还要确保在代码中正确设置了相关的active类。在这种情况下,我建议检查以下几点:
1. 确保.tab .active的元素存在于DOM中。可以在浏览器的开发者工具中检查元素是否存在。
2. 检查是否正确设置了.active类。可以在开发者工具中检查元素的类列表。
3. 确保lis[i和divs[i都存在并且是有效的DOM元素。可以使用console.log()语句在代码中输出它们的值来进行调试。
如果上述步骤都正确,但仍然出现错误,请提供更多的代码和错误信息以供进一步分析。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [关于原生js里报这个错:Cannot read properties of undefined (reading ‘classList‘) at HTMLLIElement.](https://blog.csdn.net/qq_59281339/article/details/126788226)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *2* [Vue3.0.0、VueCLI4.5.0启动运行时报错Cannot read properties of undefined (reading ‘NormalModule‘)...](https://blog.csdn.net/qq_35624642/article/details/122687145)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
- *3* [vue3 router 动态授权路由 异步加载报错 TypeError Cannot read properties of undefined (reading ‘apply...](https://blog.csdn.net/m0_67402341/article/details/123368619)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"]
[ .reference_list ]
阅读全文