Jquery自动完成从第一个字符开始

我认为之前有人问过这个问题,但我无法使用我的脚本。 当我开始输入输入字段时,例如我以字母AI开头,每个标签都包含字母A.

我只想要以字母A开头的标签。

这是我的脚本:

    .ui-autocomplete { max-height: 100px; overflow-y: auto; /* prevent horizontal scrollbar */ overflow-x: hidden; } /* IE 6 doesn't support max-height * we use height instead, but this forces the menu to always be this tall */ * html .ui-autocomplete { height: 100px; }  $(function() { $( "#tags" ).autocomplete({ source: [{ label: "Apple", value: "http://www.apple.com"}, { label: "Google", value: "http://www.google.com"}, { label: "Yahoo", value: "http://www.yahoo.com"}, { label: "Bing", value: "http://www.bing.com"}], minLength: 3, select: function(event, ui) { event.preventDefault(); $("#tags").val(ui.item.label); $("#selected-tag").val(ui.item.label); window.location.href = ui.item.value; } , focus: function(event, ui) { event.preventDefault(); $("#tags").val(ui.item.label); } }); }); 

这是我的HTML:

 

这可能与我的脚本一样吗?

提前致谢

试试这个

 var data = [ { label: "Apple", value: "http://www.apple.com" }, { label: "Google", value: "http://www.google.com" }, { label: "Yahoo", value: "http://www.yahoo.com" }, { label: "Bing", value: "http://www.bing.com" }]; $(function() { $( "#tags" ).autocomplete({ source: function( request, response ) { var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( request.term ), "i" ); response( $.grep( data, function( item ){ return matcher.test( item.label ); }) ); }, minLength: 1, select: function(event, ui) { event.preventDefault(); $("#tags").val(ui.item.label); $("#selected-tag").val(ui.item.label); window.location.href = ui.item.value; }, focus: function(event, ui) { event.preventDefault(); $("#tags").val(ui.item.label); } }); }); 

看看演示