jQuery UI 自动完成 DownArrow UpArrow
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8045773/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery UI Autocomplete DownArrow UpArrow
提问by Andy
I am having some issues with jQuery Autocomplete and moving DownArrow and UpArrow ?
我在使用 jQuery Autocomplete 和移动 DownArrow 和 UpArrow 时遇到了一些问题?
The problem seems to be that
问题似乎是
<input id="autocomplete-input" value="">
<input id="autocomplete-input" value="">
focus: function (event, ui) {
$('#autocomplete-input').val(ui.item.label);
}
This works great for MOUSE focus - but when I use arrowUp
and arrowDown
- it selects the ui.item.id
over and above the ui.item.label
这对于鼠标焦点非常有用 - 但是当我使用arrowUp
和arrowDown
- 它选择ui.item.id
超过ui.item.label
How can I fix this so that either:
我该如何解决这个问题,以便:
- the
input
val isn't changed at all [i.e. it keeps the users inputted term] - it updates the
input
val with thefocused
val the user is on with keydown/keyup
- 该
input
VAL完全不改变[即它使用户输入项] - 它
input
使用focused
用户使用 keydown/keyup的val更新val
thanks
谢谢
回答by Andrew Whitaker
Make sure to prevent the default behavior of the focus
event:
确保阻止focus
事件的默认行为:
focus: function (event, ui) {
this.value = ui.item.label;
// or $('#autocomplete-input').val(ui.item.label);
// Prevent the default focus behavior.
event.preventDefault();
// or return false;
}