我很难理解为什么我的表列搜索始终显示第一行和之后的匹配行?即使关键字与第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)
,然后它会根据匹配的行进行切换。
有什么建议吗?
答案 0 :(得分:3)
事实上,在您使用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");
以下内容:
Foldable t => (a -> Bool) -> t a -> Bool