自动完成功能永远不会在输入的第一个字符上激活虽然使用后空格后它适用于minLength = 1.
此外,selectFirst:true永远不会默认为页面加载时数组中的第一项.
此外,selectFirst:true永远不会默认为页面加载时数组中的第一项.
$().ready(function (){ $('#CompanyName').autocomplete({ source: companyNames,select: SetLocations,selectFirst :true,minLength: 0 //corrected as suggested,but still no change }); });
以前有人遇到过这种行为吗?我很无能,因为我没有任何全局设置/默认值.
解决方法
你有一些语法错误,document.ready处理程序缺少一个大括号(并且无论如何都被弃用)和你的选项中的逗号,它应该如下所示:
$(function() { $('#CompanyName').autocomplete({ source: companyNames,selectFirst: true,//here minLength: 0 }); });
此外,自动填充在minLength字符后激活,如果您想立即使用,请使用0,from the docs:
minLength: The minimum number of characters a user has to type before the Autocomplete activates. Zero is useful for local data with just a few items. Should be increased when there are a lot of items,where a single character would match a few thousand items.
…..