JQuery UI 自动完成,选择后的值(通过鼠标)与(通过箭头键)不同

发布于 2024-09-06 02:20:08 字数 347 浏览 2 评论 0原文

我将 jQuery UI Autocomplete 1.8.1Jquery 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

锦上情书 2024-09-13 02:20:08

或者您可以将其添加到选择中

select: function( event, ui ) {
    $('#input').val(ui.item.value);
}

or you can add it in select

select: function( event, ui ) {
    $('#input').val(ui.item.value);
}
流星番茄 2024-09-13 02:20:08

我有一个类似的问题。

使用键盘时,文本框的焦点会丢失,但单击时焦点会返回到文本框。

可能是您在重新触发的输入字段的焦点上发生了某些事情?

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?

他夏了夏天 2024-09-13 02:20:08

您可以执行以下操作:

$('#input').autocomplete({
   source: items,
   focus: function(event, ui) { var text = ui.item.value; 
   $('#input').val(text); 
   return false; 
   }
});

用鼠标悬停在该项目上,将用当前值填充文本框,当您单击它时,该值将已显示在文本框中

You can do something like this:

$('#input').autocomplete({
   source: items,
   focus: function(event, ui) { var text = ui.item.value; 
   $('#input').val(text); 
   return false; 
   }
});

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

ˉ厌 2024-09-13 02:20:08

解决方案是通过自动完成焦点回调内的 PreventDefault() 来停止事件

The sollution was to stop event by preventDefault() inside of autocomplete focus callback

天赋异禀 2024-09-13 02:20:08

我无法以完美的方式解决这个问题,所以我设法隐藏 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 customized div that is hidden on click the focus passed to the jQuery UI search input filed again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文