如何显示在Keyup上进行div搜索时找不到记录的消息 [英] How to display No Records Found Message for div search on keyup
本文介绍了如何显示在Keyup上进行div搜索时找不到记录的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当用户输入input时,我正在搜索div. 如果没有记录,我应该显示一条消息无记录"
I am searching the div as user enters input . Incase there are no records I should display a message a No Records
如果我在搜索中按'H'键搜索其最初显示的消息为'No Records'
Incase i press 'H' inside search its initially displaying message as 'No Records '
这是我的js代码
$('#searchequip').keyup(function()
{
var val = $.trim(this.value).toUpperCase();
$(".mt-checkbox").each(function()
{
var parent = $(this).closest('li'),
length = $(this).text().length > 0;
if (length && $(this).text().search(new RegExp(val, "i")) < 0)
{
parent.fadeOut("slow");
console.log('Nothing Found ');
$("#errmsg").html("No Results Found").show().fadeOut("slow");
}
else
{
parent.show();
}
});
})
这是我的小提琴
http://jsfiddle.net/cod7ceho/228/
推荐答案
这是代码; http://jsfiddle.net/cod7ceho/246/
$('#searchequip').keyup(function (){
var val = $.trim(this.value).toUpperCase();
var noElem = true;
$('.mt-checkbox').each(function (){
var parent = $(this).closest('li'),
length = $(this).text().length > 0;
if (length && $(this).text().search(new RegExp(val, 'i')) < 0)
{
parent.fadeOut('slow');
}else{
noElem = false;
parent.show();
}
});
if (noElem)
$('#errmsg').html('No Results Found').show().fadeOut('slow');
})
这篇关于如何显示在Keyup上进行div搜索时找不到记录的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文