添加“无结果”;进入搜索/过滤脚本

Adding "no results" into search/filter script

本文关键字:无结果 搜索 过滤 脚本 添加      更新时间:2023-09-26

我知道…另一个"没有结果"的问题……很抱歉,但我需要问一下,因为我已经和它斗争了几个小时了,几乎没有任何效果。

我得到了一些脚本来过滤项目,我需要你的帮助注入一些代码来显示"无结果"消息。

$("#my-search-input").keyup(function() {
    var search = $(this).val();
    $(".my-list").children().show();
    if (search)
       $(".my-list").children().not(":containsNoCase(" + search + ")").hide();
});

$.expr[":"].containsNoCase = function (el, i, m) {
    var search = m[3];
    if (!search) return false;
       return new RegExp(search,"i").test($(el).text());
};
这是我的小提琴:http://jsfiddle.net/bk13detv/22/

基本上消息应该显示在每个table实例中。

谢谢你的时间,干杯。

你可以尝试这样做:

    $("#my-search-input").keyup(function () {
        var search = $(this).val();
        $(".my-list").children().show();
        $('.noresults').remove();
        if (search) {
            $(".my-list").children().not(":containsNoCase(" + search + ")").hide();
            $(".my-list").each(function () {
                if ($(this).children(':visible').length == 0) 
                    $(this).append('<tr class="noresults"><td colspan="3"><em>No Results</em></td></tr>');
            });
        }
    });