我重寫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