js_for循环的错误

本段代码实现的效果是遍历数组中的每个元素,给每个元素插入一个类名

for (var i = 0; i < dropdownLi.length; i++) {
    
    
    if(i ==  1){
      continue;
    }

    // 排除掉第二个元素
    console.log(i);
      dropdownLi[i].onmouseover = function () {
    this.classList.add("show");
  }

  dropdownLi[i].onmouseout = function () {
    this.classList.remove("show");
  }
  }

bug_

其中,遇到了一个致命的问题!
关于for循环,在这里写的时候第一次写成了

for (var i = 0; i < dropdownLi.length; i++){
  if(i = 1){
  continue;
}
.......................
}

这么写造成的结果就是 浏览器无法解析这段代码,从而导致卡死

posted @ 2022-06-23 18:02  rainsc  阅读(267)  评论(0编辑  收藏  举报