[英]How to get JQuery-UI autocomplete to submit on pressing enter while using categories from remote source?
我正在从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,我如何获得输入触发器“选择”呢? 现在,如果您仅按Enter键(未从下拉菜单中选择任何内容),则下拉菜单将消失,并且什么也不会发生。 但我不希望将下拉菜单中的所有内容(即使不匹配)发送到/ displayInfo。
有什么建议么 ?
当出现自动完成搜索时,使用箭头键并按Enter键,它将自动在文本框中显示该值。 或可以使用onkeyup或onkeypress事件,然后为Enter查找event.keycode,然后使用功能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.