Search HTML table with JS and jQuery

前端 未结 5 1474
谎友^
谎友^ 2020-12-13 11:28


I made a table and wanted to make it searchable, so I googled and looked here at starckoverflow.
But somehow, the things I\'ve found, that should work, dont wo

5条回答
  •  鱼传尺愫
    2020-12-13 12:01

    I have put the part of your code that matters and wrote a working fiddle

    http://jsfiddle.net/9hGym/602/

    this is now the search engin:

        var searchText = $(this).val().toLowerCase();
        $.each($("#table tbody tr"), function() {
            if($(this).text().toLowerCase().indexOf(searchText) === -1)
               $(this).hide();
            else
               $(this).show();                
        });
    

    you can also use http://www.datatables.net/ for such things ;)

提交回复
热议问题