Live search through table rows

前端 未结 15 1863
失恋的感觉
失恋的感觉 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:29

    François Wahl approach, but a bit shorter:

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

    http://jsfiddle.net/ARTsinn/CgFd9/

提交回复
热议问题