Javascript 迭代每个jquery

Javascript 迭代每个jquery,javascript,jquery,Javascript,Jquery,我想重申她自己的观点。但它不起作用。当我通过参数时,它不会出错或更好 $('table tr').each(function () { var tr = $(this) var nivel = parseInt(tr.find('td:eq(1)').text()); var item = parseInt(tr.find('td:eq(0)').text()); if (nivel > 3) { tr.closest('tr').css(

我想重申她自己的观点。但它不起作用。当我通过参数时,它不会出错或更好

 $('table tr').each(function () {
    var tr = $(this)
    var nivel = parseInt(tr.find('td:eq(1)').text());
    var item = parseInt(tr.find('td:eq(0)').text());
    if (nivel > 3) {
        tr.closest('tr').css({ "display": "none" });
    }
    $('table tr').each(function (item) {
        var itemPai = parseInt($(this).find('td:eq(2)').text());
        if (item == itemPai) {
            console.log("Tem filhos");
            $(this).closest('tr').find('a.toggler').css({ "display": "normal" });
        } else {
            $(this).closest('tr').find('a.toggler').css({ "display": "" });
        }
    });
});

我不明白您想要实现什么,了解您的表中有哪些数据可能会有所帮助

您能确保您访问的单元格的值是数字吗?如果不是100%,请在使用
parseInt
之前使用
typeof

无论如何,在第二个循环中,来自外部循环的变量
item
可用,在函数调用中将其声明为参数将覆盖外部值

如果要比较外循环和内循环之间的值,只需从内部迭代的函数调用中删除该参数:

$('table tr').each(function () {
  var tr = $(this)
  var nivel = parseInt(tr.find('td:eq(1)').text());
  var item = parseInt(tr.find('td:eq(0)').text());
  if (nivel > 3) {
    tr.closest('tr').css({ "display": "none" });
  }
  $('table tr').each(function () {
    var itemPai = parseInt($(this).find('td:eq(2)').text());
    if (item == itemPai) {
      console.log("Tem filhos");
      $(this).closest('tr').find('a.toggler').css({ "display": "normal" });
    } else {
      $(this).closest('tr').find('a.toggler').css({ "display": "" });
    }
  });
});

你到底想做什么?你能提供一个例子吗?请注意,
tr.nestest('tr')
在功能上与只使用
tr
(与
$(this.nestest('tr')
相同)