使整个表可搜索

时间:2017-04-21 12:50:17

标签: javascript jquery

我正在尝试使用搜索栏搜索表格。我添加了一个代码,但它只搜索表的第一列。我想让表格的所有列都可以搜索。你能指导我怎么办?这是我的代码。

$("#search").on("keyup", function() {
    var value = $(this).val();

    $(".table tr").each(function(index) {
        if (index !== 0) {

            $row = $(this);

            var id = $row.find("td:first").text();

            if (id.indexOf(value) !== 0) {
                $row.hide();
                //$row.html('Records not found!');

                //$(".norecord").html('<td colspan="9">Records not found!</td>');
            }
            else {
                $row.show();

            }
        }


    });
});

2 个答案:

答案 0 :(得分:0)

删除&#39;:第一个&#39;从您的查询$row.find("td").text()应该返回该行所有列的文本。

答案 1 :(得分:0)

我会使用正则表达式而不是“indexOf”。像这样的东西:

display:flex; align-items:center;

DEMO:https://jsfiddle.net/7qkgf14d/1/

然后,如果需要,您可以指定要搜索的列。

相关问题