我重写jQuery的自动完成功能显示简单的链接(<a href=...>
“)和一些额外的格式,将需要更复杂的后成为点击。在点击链接时不能使链接在jQuery的自动完成
什么也没有发生。有一种方法来消除任何事件处理程序或其他代码被拦截的点击,使他们像预期的那样?
有几个相关的问题(如#4536055)具有良好的答案,但他们处理的默认自动完成的行为。该source
答案似乎像黑客 - 链接应该像链接功能。
我的代码:
$.widget("custom.complete_custom", $.ui.autocomplete, {
_renderMenu: function(ul, items) {
// Trigger a "See all" link if there are two many results
var self = this;
var too_long = false;
if (items.length > 10){
original_length = items.length;
too_long = true;
items = items.slice(0,10);
}
// Display each result as a link
$.each(items, function(index, item) {
ul.append("<li class='ui-autocomplete-category'><a href='/building/" + item.buildingcode + "'>" + item.buildingname + "</a></li>");
});
// Add the "See all" link if necessary
if(too_long) {
ul.append("<li class='ui-autocomplete-category see-all'><a href='/search/" + 'term' + "'><strong>See all " + original_length + " results</strong></a></li>")
}
}
});
// The autocomplete activator
$("#search").complete_custom({
source: "/search/json",
minLength: 2
});
您是否找到了解决办法? – simPod 2012-05-26 15:25:48