0
由于输入中的用户类型,我正在搜索表格并相应地显示结果。如何在此代码中仅使用一列进行表格搜索
目前有两款TD在表名称和课程
,才有可能使搜索只为名称,但当然不是
目前这两个(名称和课程)
这是我的代码
$(document).ready(function()
{
$('#searchinputtext').keyup(function()
{
var tr = $('#videosfromtagstable tbody tr'); //use tr not td
if ($(this).val().length >= 2) {
var inputdata = $.trim($("#searchinputtext").val());
$('#errmsgnovideos').hide();
var noElemvideo = true;
var val = $.trim(this.value).toLowerCase();
el = tr.filter(function()
{
return this.innerHTML.toLowerCase().indexOf(val) >= 0;
}); // <==== closest("tr") removed
if (el.length >= 1)
{
noElemvideo = false;
}
//now you fadeIn/Out every row not every cell
tr.not(el).fadeOut();
el.fadeIn();
if (noElemvideo)
if (inputdata !== '')
{
$('#errmsgnovideos').html('No Results Matched').show();
}
else
{
$('#errmsgnovideos').hide();
}
}
else {
tr.fadeIn(); //show all if length does not match the required number of characters
$('#errmsgnovideos').hide();
}
})
});
http://jsfiddle.net/e08o7uct/30/
非常感谢。简单而高效。 – Pawan