[英]Resig's Live Search redux for jQuery 1.7 and above?
I recently found Resig's jQuery rewrite of a Quicksilver Live Search and love the workings of it... but I'm trying to update it to work with the new .on() event handler. 我最近发现Resig的jQuery 重写了Quicksilver Live Search,并喜欢它的工作原理...但是我正在尝试对其进行更新,以与新的.on()事件处理程序一起使用。 However my abilities (or lack thereof) fail me.
但是我的能力(或缺乏能力)使我失望。
I'm thinking I need to edit the "this.keyup(filter)..." but I get nothin' to work. 我在想我需要编辑“ this.keyup(filter)...”,但是我什么也没做。 Any ideas?
有任何想法吗?
Update: Just a point of clarification. 更新:只是澄清一点。 My thoughts as to wanting to update the script is to accept list items brought in dynamically.
我想更新脚本的想法是接受动态引入的列表项。 Everything works fine as long as it's a static list, but since I have introduced a list created via an ajax call, it fails to work.
只要它是静态列表,一切都可以正常工作,但是由于我介绍了通过ajax调用创建的列表,因此它无法正常工作。 I'm going to mock up a fiddle and link it here shortly.
我将模拟一个小提琴并将其链接到此处。 In the meantime, if anyone can help me out, it'd save my hide.
同时,如果有人可以帮助我,那将节省我的皮革。 Thanks.
谢谢。
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();
});
}
}
};
So by chance I ran across this post which, with the assistance of jfk , pretty much summed up what I was looking for. 因此,我偶然碰到了这篇帖子 ,在jfk的帮助下,几乎可以总结出我想要的内容。 I was wanting to make the script run after dynamic content was created, when what I should have been doing was call the script when the user is wanting to make a search.
我想让脚本在创建动态内容之后运行,而当用户想要进行搜索时,我应该做的就是调用脚本。
$('#staticParent').on("click", "#searchField", function(){
$(this).livesearch("#dynamicElements").focus();
});
Any additional info from more advanced developers on making this better, I'm all ears. 我很高兴听到更多更高级的开发人员提供的有关使此操作变得更好的信息。 I hope this can one day help another.
我希望这可以有一天帮助另一人。 :)
:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.