添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
奔跑的骆驼  ·  Electron30 ...·  1 月前    · 
虚心的炒面  ·  String decoder | ...·  1 月前    · 
纯真的羽毛球  ·  constexpr (C++) | ...·  2 周前    · 
机灵的炒面  ·  android JobScheduler ...·  1 年前    · 
欢乐的镜子  ·  break | Microsoft Learn·  1 年前    · 
爱搭讪的长颈鹿  ·  .net core - Castle ...·  2 年前    · 
腹黑的香瓜  ·  Linux / ...·  2 年前    · 
谦和的电池  ·  定义目标模型·  2 年前    · 

当我在循环遍历dom元素的时候,报了想下面这种错误
Uncaught TypeError: Cannot read properties of undefined (reading 'classList')

我的代码是这样的

                allStopVfor(tdClass) {
                    setTimeout(() => {
                        const tdStopVfor = document.querySelectorAll(tdClass)
                        for (let i = 1; i <= tdStopVfor.length; i++) {    
                            tdStopVfor[i].classList.add('active')

然后在别的地方调用了它,最后控制台一直报那种错误

最后我在添加classList.add 之前添加了个判断

                allStopVfor(tdClass) {
                    setTimeout(() => {
                        const tdStopVfor = document.querySelectorAll(tdClass)
                        for (let i = 1; i <= tdStopVfor.length; i++) {
                            if (tdStopVfor[i]) {
                                tdStopVfor[i].classList.add('active')

最后问题解决了

最后的可能因素,应该是数据的问题吧

分类:
前端
标签: