是的,我知道......另一个“没有结果”的问题......对此感到抱歉,但我需要问,因为我现在正在与它战斗几个小时,几乎没有任何效果。
我有一些脚本来过滤项目,我需要您的帮助来注入(inject)一些代码来显示“无结果”消息。
$("#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());
};
这是我的 fiddle : http://jsfiddle.net/bk13detv/22/
基本上消息应该显示在表的每个实例中。
感谢您的宝贵时间,干杯。
最佳答案
你可以尝试这样的事情:
$("#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>');
});
}
});
查看此Fiddle进行演示。
关于javascript - 将 "no results"添加到搜索/过滤脚本中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31325887/