【发布时间】:2015-02-05 04:33:11
【问题描述】:
我正在使用来自 jqueryui 站点的以下样板代码: http://jqueryui.com/autocomplete/#categories http://jqueryui.com/autocomplete/#remote
$.widget("custom.catcomplete", $.ui.autocomplete, {
_create: function() {
this._super();
this.widget().menu("option", "items", "> :not(.ui-autocomplete-category)");
},
_renderMenu: function(ul, items) {
var that = this,
currentCategory = "";
$.each(items, function(index, item) {
var li;
if (item.category != currentCategory) {
ul.append("<li class='ui-autocomplete-category'>" + item.category + "</li>");
currentCategory = item.category;
}
li = that._renderItemData(ul, item);
if (item.category) {
li.attr("aria-label", item.category + " : " + item.label);
}
});
},
});
$(function() {
$("#search").catcomplete({
delay: 0,
source: "search",
select: function(event, ui) {
ajax.get("/displayInfo", {
a: ui.item.value
}, displayInfo, true);
}
});
});
但是即使用户只是按下回车,我如何获得输入触发器“选择”?现在,如果您只是按 Enter 键(不从下拉菜单中选择任何内容),下拉菜单就会消失并且什么也不会发生。但我不想将下拉列表中的任何内容(即使它不匹配)发送到 /displayInfo。
有什么建议吗?
【问题讨论】:
-
当建议列表为open,
ui参数为空...我认为这并不容易,您可能需要提出功能请求@bugs.jqueryui.com -
我想这是一个非常常见的用例,我认为肯定有其他人已经有这个要求,或者想出了一个解决方法..
-
嗯,这对我来说也是一个常见的用例,这就是为什么我建议提出功能请求.. :)
标签: javascript jquery jquery-ui autocomplete