jquery 自动完成触发下拉输入:焦点 [英] jquery autocomplete trigger dropdown on input:focus
问题描述
我正在使用下面流行的 JQuery 自动完成插件.
I'm using the popular JQuery Autocomplete plugin below.
http://jqueryui.com/demos/autocomplete/
目前,如果您输入短语,下拉菜单会出现,但当您单击离开时,它会隐藏.这可以.但是,恢复下拉菜单的唯一方法是单击输入字段并输入更多字符或按下 keydown.
Currently if you type a phrase the drop down appears but when you click away it hides. This is fine. However the only way to bring the dropdown back is to either click in the input field and type further characters or press keydown.
关于如何在用户单击输入字段时触发结果下拉列表的任何想法?我试图触发输入字段的焦点事件,但这不起作用.当输入字段被聚焦时,我不知何故需要手动调用自动完成下拉事件.谢谢.
Any ideas on how to trigger the dropdown of results when the user clicks in the input field? I've tried to trigger the focus event for the input field but that doesn't work. I somehow need to manually call the autocomplete dropdown event when the input field is focused. Thanks.
推荐答案
工作演示 http://jsfiddle.net/CNYCS/
酷;所以你需要做的就是 bind
焦点事件与自动完成,其余的`自动完成将从那里接管,正如你在演示中看到的那样.
Cool; so all you need to do is bind
focus event with the autocomplete, rest `autocomplete will take over from there as you can see in the demo.
有用链接:http://forum.jquery.com/topic/how-to-bind-focus-input-to-trigger-autocomplete & http://docs.jquery.com/UI/Autocomplete#method-search
希望这会有所帮助,
其余代码在 jsfiddle 中.
Rest code is in jsfiddle.
代码
$( "#tags" ).autocomplete({
source: availableTags,
minLength:0
}).bind('focus', function(){ $(this).autocomplete("search"); } );
这篇关于jquery 自动完成触发下拉输入:焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!