代码之家  ›  专栏  ›  技术社区  ›  KJSR

Jquery搜索不隐藏表中的第一行

  •  1
  • KJSR  · 技术社区  · 7 年前

    这是我的工作代码

    $('#filterbyname').on("keyup", function () {
            var val = $(this).val();
            var matches = $("table.bill tr:not(:first-of-type)");
    
            matches.each(function (i,e) {            
                debugger;
                $row = $(this);                
                $cells = $row.find("td:nth-child(2)");
    
                $cells.each(function (i2, e2) {
                    var cell = $(this).text();
                    debugger;
                    $row.toggle(cell.indexOf(val) >= 0);             
                });
            });
     });
    

    从上面的代码中可以看出 cell.indexOf(val) >= 0) 然后它将根据匹配的行进行切换。

    有什么建议吗?

    1 回复  |  直到 7 年前
        1
  •  3
  •   Fueled By Coffee    7 年前

    事实上,在你的 matches 您正在使用的变量 tr:not(:first-of-type) :not :first-of-type 在这里,这意味着他们不是父母中的第一个孩子,所以第一个 tr

    更改此代码:

    var matches = $("table.bill tr:not(:first-of-type)");
    

    var matches = $("table.bill tr");