
index.js:37 Uncaught TypeError: Cannot set property ‘className’ of undefined
at Tab.clear (index.js:37)
at HTMLLIElement.taggleList (index.js:24)
写代码的时候发生了这个错误
代码如下

发现原来是获取section的时候queryselectorAll写成了queryselector,只获取了第一个section,然后到了clear那里,循环3次,匹配的时候就出现了错误,而且queryselector或取的不是数组,因为没有section[i]这个元素,所以不能设置这个classname这个属性。
在执行JavaScript代码时遇到了'Uncaught TypeError: Cannot set property ‘className’ of undefined'的错误。问题源于将querySelector误写为querySelectorAll,导致只获取到第一个section元素。在clear函数中遍历时,由于没有正确选取所有section,尝试设置不存在的className属性,从而引发错误。解决方案是修正查询选择器以获取所有section元素。

391

被折叠的 条评论
为什么被折叠?



