[英]Adding "no results" into search/filter script
yea I know ... another "no results" question ... sorry for that, but i need to ask because i'm fighting with it couple of hours now and preety much nothing works.是的,我知道......另一个“没有结果”的问题......抱歉,但我需要问,因为我现在正在与它斗争几个小时并且几乎没有任何效果。
I got some script to filter items and I need your help to inject some code to display "no results" message.我有一些脚本来过滤项目,我需要你的帮助来注入一些代码来显示“无结果”消息。
$("#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());
};
Here's my fiddle: http://jsfiddle.net/bk13detv/22/这是我的小提琴: http : //jsfiddle.net/bk13detv/22/
Basically message should display in every instance of table.基本上消息应该显示在表的每个实例中。
Thanks for your time, cheers.谢谢你的时间,干杯。
You could try something like this:你可以尝试这样的事情:
$("#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>');
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.