【发布时间】:2014-02-04 16:28:17
【问题描述】:
我已经使用 jQuery UI 为多个值实现了自动完成功能。它工作正常,但问题是我不想从下拉列表中显式选择值(使用选项卡)。我的要求是,当我浏览下拉菜单时,我的搜索框应该被填充。然后我进入昏迷状态并再次从下拉列表中继续搜索。
我基本上尝试了 jqueryUI Autocomplete 中的那段代码,但焦点已被抑制。我想要的是,我们应该能够使用焦点选择它,然后用逗号继续搜索,而不是选择选项卡上的项目。
.autocomplete({
minLength: 0,
source: function( request, response ) {
// delegate back to autocomplete, but extract the last term
response( $.ui.autocomplete.filter(productNames, extractLast(request.term)));
},
focus: function() {
// prevent value inserted on focus
//this.value = ui.item.value;
return false;
},
select: function( event, ui ) {
var terms = split( this.value );
// remove the current input
terms.pop();
// add the selected item
terms.push( ui.item.value );
// add placeholder to get the comma-and-space at the end
terms.push( "" );
this.value = terms.join( ", " );
return false;
}
【问题讨论】:
标签: javascript jquery autocomplete jquery-ui-autocomplete