我正在使用jQuery AutoComplete UI小部件,例如:

var names = ["John", "Jack", "Nick", "Tom", "Joyce", "Nancy"];
$("#nameInput").autocomplete({
    source: names
});

我希望它像Gmail的“到”文本框一样行为。

具体来说,我希望它在输入时突出显示最佳匹配,如果您按Enter,则选择突出显示的值。

换句话说,我不想使用上/向下箭头或鼠标进行选择。

感谢您的建议!

有帮助吗?

解决方案

由于在输入时会产生自动完成过滤器,因此您只需要自动敲击第一个结果即可。

//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.
});
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top