自动选择第一个jquery UI结果 [英] Select first jquery UI result automatically
问题描述
我正在使用jQuery Autocomplete来搜索城市的本地数据库。以下是代码:
I am using jQuery Autocomplete to search a local database of cities. Here is the code:
$('#txt_search_city').autocomplete({
source: url,
delay: 0,
autoFocus: true,
select: function( event, ui ) {
$( "#id_city" ).val( ui.item.id );
$(this).closest('form').submit();
},
focus: function( event, ui ) { event.preventDefault(); }
});
我希望默认选择第一个返回值(就像在facebook上一样)。所以基本上,如果他们只是点击输入,他们将触发第一个结果的选择。
I'd like the first returned value to be selected by default (like it works on facebook). So essentially, if they just hit enter they will trigger the selection of the first result.
我认为这是什么 autoFocus:true
没有,但它不起作用。没有显示错误,只是没有选择第一个结果。
I thought that's what autoFocus: true
did, but it isn't working. Not showing errors, just not selecting the first result.
想法?
推荐答案
自动对焦将突出显示第一条记录..
Autofocus will highlight the first record..
您的代码只需要包含 autoFocus:true
,如下所示:
Your code would then just need to include autoFocus: true
, like below:
$('#txt_search_city').autocomplete({
source: url,
delay: 0,
autoFocus: true,
select: function( event, ui ) {
$( "#id_city" ).val( ui.item.id );
$(this).closest('form').submit();
},
focus: function( event, ui ) { event.preventDefault(); }
});
这篇关于自动选择第一个jquery UI结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!