Live search through table rows

前端 未结 15 1864
失恋的感觉
失恋的感觉 2020-11-29 00:52

I want to do a live search through the table rows, using jQuery, the \"live\" word is the key, because I want to type the keywords in the text input, on the same site and I\

15条回答
  •  无人及你
    2020-11-29 01:34

    Here's a version that searches both columns.

    $("#search").keyup(function () {
        var value = this.value.toLowerCase().trim();
    
        $("table tr").each(function (index) {
            if (!index) return;
            $(this).find("td").each(function () {
                var id = $(this).text().toLowerCase().trim();
                var not_found = (id.indexOf(value) == -1);
                $(this).closest('tr').toggle(!not_found);
                return not_found;
            });
        });
    });
    

    demo: http://jsfiddle.net/rFGWZ/369/

提交回复
热议问题