jQuery UI autocomplete show results before search

自作多情 提交于 2019-12-08 01:36:37

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!