Javascript函数进入循环

时间:2016-10-28 22:24:29

标签: javascript

我的项目中有以下功能: -

function RowSelection() {
  var table = document.getElementById("tbl_Audit");
  if (table != null) {
    for (var x = 0; x < table.rows.length; x++) {
      for (var j = 0; j < table.rows[x].cells.length; j++) {
        if (j = 4) {
          alert("condition passed " + j)
          table.rows[x].cells[j].onclick = function() {
            tableText(this);
          }
        }
      }
    }
  }
}

当触发此功能时,它会进入一个永无止境的循环。任何人都可以帮我确定我在这里做错了什么。

1 个答案:

答案 0 :(得分:4)

//I want this computed to trigger on obs1 update but ignore updates to obs2 this.comp2 = ko.computed(function() { return self.obs1() + self.obs2.peek(); }, self); 更改为if (j=4)

if (j===4)是一个赋值,这不是语法错误,因此代码会运行,但会将=的值更改为j,因此(假设4小于细胞数量)你的循环条件总是如此。