jQuery的自动完成响应进入关键
问题描述:
我使用jQuery UI自动完成窗口小部件,例如:jQuery的自动完成响应进入关键
var names = ["John", "Jack", "Nick", "Tom", "Joyce", "Nancy"];
$("#nameInput").autocomplete({
source: names
});
我想它的行为像Gmail的“到”文本框。
具体而言,我希望在您键入时突出显示最佳匹配,并且如果按下回车键,则会选中突出显示的值。
换句话说,我不想使用上/下箭头或鼠标进行选择。
感谢您的任何建议!
答
由于自动完成过滤器在键入时产生结果,因此您只需自动高亮显示第一个结果。
//PSEUDO CODE
$('input').autocomplete({
source: //your code to link to the source,
open: //your code to select the first element, I cannot see there is a built-in method to select the first option, but you could firebug the menu and use css class to target the correct element.
});