问题
I want in my project to show some first results before I focus autocomplete input. Those results should work the same way as results of autocomplete ajax request.
Can I do this by standart options of autocomplete or I should write equal javascript code?
回答1:
You should set the minLength
option to 0
. If you want results to appear as soon as the field is focused into, you could write a simple event handler to accomplish that:
$("input").autocomplete({
source: /* source */,
minLength: 0
}).on("focus", function () {
$(this).autocomplete("search", '');
});
Example: http://jsfiddle.net/mLSjL/
Edit: If you want to show the suggestion list immediately, try showing it on the create
event of the autocomplete widget:
$("input").autocomplete({
source: /* source */,
minLength: 0,
create: function () {
$(this).autocomplete("search", '');
}
});
Example: http://jsfiddle.net/CVUWV/
来源:https://stackoverflow.com/questions/11758821/jquery-ui-autocomplete-show-results-before-search