JQuery UI 自动完成,选择后的值(通过鼠标)与(通过箭头键)不同
我将 jQuery UI Autocomplete 1.8.1
与 Jquery 1.4.2
一起使用,但遇到了这个问题。
起初,我无法强制自动完成输入字段的值,这不是一个大问题。
但我有一个问题:
当用户使用鼠标选择
选项时,我的行为与使用键盘箭头不同。使用键盘时,一切正常,并且在输入文本框中选择后会出现该值,但使用鼠标时,它会保留旧的(键入的)值而不是选定的值。
如何控制它(选择后的文本框值)?以及为什么会有不同的行为?
PS:改变select
函数内输入框的值是没有用的,因为它无法完成!
I'm using jQuery UI Autocomplete 1.8.1
with Jquery 1.4.2
and I have this issue.
At first, I can't force the value of the Autocomplete input field, well this is not a big problem.
But I have this issue with it:
I doesn't act similarly when a user select
a choice using mouse to using keyboard arrows. When using keyboard everything is fine and the value appears after select in the input text box, but when using mouse it sticks with the old (typed) value not the selected one.
How to control this (textbox value after select)? and why there are different behaviours?
P.S: changing the value of the input box inside the select
function is useless since it can't be done!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
或者您可以将其添加到选择中
or you can add it in select
我有一个类似的问题。
使用键盘时,文本框的焦点会丢失,但单击时焦点会返回到文本框。
可能是您在重新触发的输入字段的焦点上发生了某些事情?
I had a similar problem to this.
When using the keyboard the focus from the text box is lost, but on click the focus goes back to the text box.
It could be that you have something happening on the focus of the input field which is being re-triggered?
您可以执行以下操作:
用鼠标悬停在该项目上,将用当前值填充文本框,当您单击它时,该值将已显示在文本框中
You can do something like this:
Hovering the item with the mouse, will fill the textbox with the current value, and when you click into it the value will be already displayed on the textbox
解决方案是通过自动完成焦点回调内的 PreventDefault() 来停止事件
The sollution was to stop event by preventDefault() inside of autocomplete focus callback
我无法以完美的方式解决这个问题,所以我设法隐藏
select
上的搜索输入字段,并显示另一个在单击焦点时隐藏的自定义div
再次传递到jQuery UI
搜索input
字段。I couldn't solve it in the prefect way, So I've managed to hide the search input field on
select
and display another customizeddiv
that is hidden on click the focus passed to thejQuery UI
searchinput
filed again.