jQueryUI的自动完成:自动对焦=真不会做任何事情 [英] JqueryUI Autocomplete: autoFocus = true won't do anything
问题描述
我有自动完成功能,该输入:
i have this input with autocomplete feature:
.autocomplete({
source: "jsonR.php",
minLength: 2,
select: function( event, ui ) {
$(this).val(ui.item.value);
llamar('/includes/router.php?nomenu=1&que=view_item&id='+ui.item.id,'router');
return false;
},
autoFocus: true
,open: function() {
$('.ui-autocomplete').addClass('searchBox');
}
})
基本上我想要的功能,选择第一项,所以如果用户点击输入搜索第一
但是这不会悬停/重点的第一项建议,
Basically i want the feature to select the first item so if user hits enter it searches the first one but this wont hover/focus the first item suggested,
任何想法,为什么?
PS:剩下的工作得很好,面团
ps: the rest works fine, dough
推荐答案
斯科特·冈萨雷斯写了selectfirst插件这一点。
Scott Gonzalez wrote a selectfirst plugin for this.
查看详细信息点击这里:<一href=\"http://forum.jquery.com/topic/autocomplete-automatically-select-first-item-in-dropdown-or-add-item-into-drop-down-menu\" rel=\"nofollow\">http://forum.jquery.com/topic/autocomplete-automatically-select-first-item-in-dropdown-or-add-item-into-drop-down-menu
See the details here: http://forum.jquery.com/topic/autocomplete-automatically-select-first-item-in-dropdown-or-add-item-into-drop-down-menu
您可以在这里下载插件:<一href=\"https://github.com/scottgonzalez/jquery-ui-extensions/blob/master/autocomplete/jquery.ui.autocomplete.selectFirst.js\" rel=\"nofollow\">https://github.com/scottgonzalez/jquery-ui-extensions/blob/master/autocomplete/jquery.ui.autocomplete.selectFirst.js
You can download the plugin here: https://github.com/scottgonzalez/jquery-ui-extensions/blob/master/autocomplete/jquery.ui.autocomplete.selectFirst.js
更好的是,这里是插件的源$ C $ C:)
better yet, here is the source code of the plug-in :)
/*
* jQuery UI Autocomplete Select First Extension
*
* Copyright 2010, Scott González (http://scottgonzalez.com)
* Dual licensed under the MIT or GPL Version 2 licenses.
*
* http://github.com/scottgonzalez/jquery-ui-extensions
*/
(function( $ ) {
$( ".ui-autocomplete-input" ).live( "autocompleteopen", function() {
var autocomplete = $( this ).data( "autocomplete" ),
menu = autocomplete.menu;
if ( !autocomplete.options.selectFirst ) {
return;
}
menu.activate( $.Event({ type: "mouseenter" }), menu.element.children().first() );
});
}( jQuery ));
请注意:使用这只是该行添加到您自动完成:
NOTE: to use this simply add this line to your autocomplete:
selectFirst: true, // auto selects first element
这篇关于jQueryUI的自动完成:自动对焦=真不会做任何事情的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!