Javascript jquery结果活动筛选器使用表
首先,我必须承认,我对JS或Jquery非常不好,这很重要。我搜索了可以帮助我使用jquery筛选结果的代码。代码如下:Javascript jquery结果活动筛选器使用表,javascript,jquery,html,Javascript,Jquery,Html,首先,我必须承认,我对JS或Jquery非常不好,这很重要。我搜索了可以帮助我使用jquery筛选结果的代码。代码如下: $(document).ready(function(){ $("#filter").keyup(function(){ // Retrieve the input field text and reset the count to zero var filter = $(this).val(), count = 0
$(document).ready(function(){
$("#filter").keyup(function(){
// Retrieve the input field text and reset the count to zero
var filter = $(this).val(), count = 0;
// Loop through the comment list
$(".commentlist li").each(function(){
// If the list item does not contain the text phrase fade it out
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).fadeOut();
// Show the list item if the phrase matches and increase the count by 1
} else {
$(this).show();
count++;
}
});
// Update the count
var numberItems = count;
$("#filter-count").text("Number of Comments = " + count);
});
});
$(文档).ready(函数(){
$(“#过滤器”).keyup(函数(){
//检索输入字段文本并将计数重置为零
var filter=$(this).val(),count=0;
//循环浏览注释列表
$(“.commentlist li”).each(函数(){
//如果列表项不包含文本短语,请将其淡出
if($(this.text().search(newregexp(filter,“i”))<0){
$(this.fadeOut();
//如果短语匹配,则显示列表项并将计数增加1
}否则{
$(this.show();
计数++;
}
});
//更新计数
var numberItems=计数;
$(“#过滤器计数”).text(“注释数=”+count);
});
});
此代码适用于下面列出的无序列表:
<ol class="commentlist"> <li>Comment #1</li> <li>Comment #2</li></ol>
评论#1 评论#2
现在,这段代码对列表非常有效。然而,我的站点中有一个表,每行有3条记录。每个记录(单元格)表示用户配置文件。我希望这个精确的搜索功能能够在表上工作,这样用户就可以键入用户名,并将其显示出来。可能吗
谢谢大家,非常感谢大家的支持,
<script>
$(document).ready(function(){
$("#filter").keyup(function(){
// Retrieve the input field text and reset the count to zero
var filter = $(this).val(), count = 0;
// Loop through the comment list
$(".users td").each(function(){
// If the list item does not contain the text phrase fade it out
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).fadeOut();
// Show the list item if the phrase matches and increase the count by 1
} else {
$(this).show();
count++;
}
});
// Update the count
var numberItems = count;
$("#filter-count").text("msg" + count);
});
});
</script>
$(文档).ready(函数(){
$(“#过滤器”).keyup(函数(){
//检索输入字段文本并将计数重置为零
var filter=$(this).val(),count=0;
//循环浏览注释列表
$(“.users td”).each(function(){
//如果列表项不包含文本短语,请将其淡出
if($(this.text().search(newregexp(filter,“i”))<0){
$(this.fadeOut();
//如果短语匹配,则显示列表项并将计数增加1
}否则{
$(this.show();
计数++;
}
});
//更新计数
var numberItems=计数;
$(“#过滤器计数”).text(“msg”+计数);
});
});