【发布时间】:2017-11-25 06:25:27
【问题描述】:
我很难理解为什么我对表格列的搜索总是显示第一行和之后的匹配行?即使关键字与第 1 行中的单元格不匹配,它也会始终显示在顶部?我已经多次检查了我的代码并尝试了不同的方法,它仍然不会隐藏第一行?
这是我的工作代码
$('#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),那么它将根据匹配的行进行切换。
有什么建议吗?
【问题讨论】:
-
这是由于
tr:not(:first-of-type)。
标签: javascript jquery html css css-selectors