0
我最近发现Resig的jQuery rewrite of a Quicksilver Live Search,并喜欢它的工作原理......但我试图更新它以使用新的.on()事件处理程序。然而,我的能力(或缺乏)使我失败。Resig的Live Search for jQuery 1.7及以上版本?
我想我需要编辑“this.keyup(filter)...”但我没有什么工作。有任何想法吗?
更新:只是澄清一点。我想要更新脚本的想法是接受动态引入的列表项。只要它是一个静态列表,一切都可以正常工作,但由于我已经引入了通过ajax调用创建的列表,因此无法工作。我会模拟一个小提琴并很快将其链接到这里。与此同时,如果任何人都可以帮助我,它会拯救我的皮。谢谢。
jQuery.fn.liveUpdate = function(list){
list = jQuery(list);
if (list.length) {
var rows = list.children('li'),
cache = rows.map(function(){
//return this.innerHTML.toLowerCase();
return $('a', this)[0].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();
});
}
}
};