从下拉列表中选择后,停止 jQuery 自动完成将输入字段聚焦
我正在使用 http://bassistance.de/jquery- 的 jQuery 自动完成插件插件/jquery-plugin-autocomplete/ 当用户从下拉列表中选择结果时,输入字段将获得焦点。我怎样才能阻止插件这样做? 我使用这篇文章中的提示使其工作: jQuery 自动完成插件不聚焦下一个单击的字段 但这仅在用户使用鼠标选择结果时才有效。然后输入字段不会获得焦点。但是当用户使用 ENTER 键或 TAB 键时,输入仍然获得焦点。
任何人都知道我如何更改此设置,以便当用户从下拉列表中选择一个值时,输入字段不会获得焦点?
预先非常感谢您!
问候,金
I'm using the jQuery autocomplete plugin from http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/
When a user selects a result from the dropdown, the input field gets focused. How can I stop the plugin from doing that?
I made it work using the tip from this post: jQuery autocomplete plugin not focusing the next clicked field
But this only works when the user uses the mouse to select the results. Then the input field doesn't get focussed. But when the user uses the ENTER-key or the TAB-key, the input still get's focus.
Anyone knows how I can change this so that when a user has selected a value from the dropdown, the input field ddoen't get focussed?
Thank you very much in advance!
Regards, Kim
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
从插件的
selectCurrent()
函数中这一行的外观来看:...每当通过鼠标或键盘选择选项时,自动完成输入上就会触发“结果”事件。
您可以绑定到同一事件并将焦点放在表单中的下一个控件上(我认为这就是您想要的,而不是仅仅从当前控件中删除焦点?):
By the looks of this line in the plugin's
selectCurrent()
function:...a "result" event is triggered on the autocomplete input whenever an option is selected, by mouse or by keyboard.
You can bind to that same event and put the focus on the next control in the form (which I assume is what you want, rather than just removing focus from the current one?):
您是否尝试过 jQuery UI 的自动完成插件?问题已经解决了一半——当您按 Tab 关闭自动完成功能时,输入字段会失去焦点。当按 Enter 时,它仍然是焦点,但这可以轻松修复:
编辑
jQuery 标准化
event
对象,因此不需要将其作为参数传递。Have you tried jQuery UI's autocomplete plugin? Half of the problem is solved – when you press Tab to close the autocomplete, the input field loses focus. When pressing Enter, it's still focused, but this can be fixed easily:
Edit
jQuery normalizes the
event
object, so passing it as an argument is unneccessary.