我正在寻找一个不错的快速实时搜索/过滤器。
有人用这个吗? http://rikrikrik.com/jquery/quicksearch/#usage 另外,如何将其与分页或 ajax 结合起来处理大量数据?
代码:
HTML:
<form method="get" autocomplete="off" action="">
<input type="text" value="" name="q" id="q"><br><br>
</form>
<ul id="posts">
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
JS:
$('#q').liveUpdate('#posts');
使用它作为插件:
jQuery.fn.liveUpdate = function(list){
list = jQuery(list);
if ( list.length ) {
var rows = list.children('li'),
cache = rows.map(function(){
return this.innerHTML.toLowerCase();
});
this
.keyup(filter).keyup()
.parents('form').submit(function(){
return false;
});
}
return this;
function filter(){
var term = jQuery.trim( jQuery(this).val().toLowerCase() ), scores = [];
if ( !term ) {
rows.show();
} else {
rows.hide();
cache.each(function(i){
var score = this.score(term);
if (score > 0) { scores.push([score, i]); }
});
jQuery.each(scores.sort(function(a, b){return b[0] - a[0];}), function(){
jQuery(rows[ this[1] ]).show();
});
}
}
};
最佳答案
关于jquery 实时搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1328417/