使用jQuery对多个具有标题的列表进行Keyup筛选
我正试图用jQuery在keyup上过滤多个带有标题(类别名称)的列表(特定类别的书籍)。我只想筛选搜索列表中的项目(特定书籍),而不想筛选标题。如果列表为空,则标题(类别名称)应消失。到目前为止,我所做的工作是过滤多个列表,但是如果列表为空,标题不会消失。我还想从筛选器中排除.custom books列表 HTML: 有什么想法吗 谢谢你,向你击掌!使用jQuery对多个具有标题的列表进行Keyup筛选,jquery,list,filter,keyup,Jquery,List,Filter,Keyup,我正试图用jQuery在keyup上过滤多个带有标题(类别名称)的列表(特定类别的书籍)。我只想筛选搜索列表中的项目(特定书籍),而不想筛选标题。如果列表为空,则标题(类别名称)应消失。到目前为止,我所做的工作是过滤多个列表,但是如果列表为空,标题不会消失。我还想从筛选器中排除.custom books列表 HTML: 有什么想法吗 谢谢你,向你击掌! Mike在这里,这将过滤它们,忽略字符串开头的第一个列表。如果你需要更具体的东西,请告诉我 var $products = $('#workfl
Mike在这里,这将过滤它们,忽略字符串开头的第一个列表。如果你需要更具体的东西,请告诉我
var $products = $('#workflow_books ul:not(:first)');
$("#search").keyup(function() {
var input = this.value;
$products.each(function() {
var $this = $(this),
$matches = $this.children('li').filter(function() {
return $(this).children('a').text().toLowerCase().indexOf(input) === 0;
});
if($matches.length > 0) {
$this.children().hide();
$this.parent().show();
$matches.show();
} else {
$this.parent().hide();
}
});
});
你的正则表达式是什么?我看不出它的定义。
var $products = $('#workflow_books li ul li a')
$("#search").keyup(function() {
$products.show().filter(function() {
return !re.test($(this).text());
}).hide();
})
var $products = $('#workflow_books ul:not(:first)');
$("#search").keyup(function() {
var input = this.value;
$products.each(function() {
var $this = $(this),
$matches = $this.children('li').filter(function() {
return $(this).children('a').text().toLowerCase().indexOf(input) === 0;
});
if($matches.length > 0) {
$this.children().hide();
$this.parent().show();
$matches.show();
} else {
$this.parent().hide();
}
});
});
var $products = $('#workflow_books li ul:not(:first)');
$("#search").keyup(function() {
var val = this.value.trim();
if(!val) $('li:hidden', '#workflow_books').show();
else {
$('li:hidden', $products).show();
$('li', $products).filter(function() {
var re = new RegExp(val, 'ig');
return !re.test($('a', this).text());
}).hide();
$products.each(function() {
if($('li:visible', this).length == 0) $(this).parent('li').hide();
else $(this).parent('li').show();
});
}
});