使用不带ajax的jquery自动完成

vik*_*234 0 javascript jquery autocomplete

我很遗憾再次提出这个问题.我正在尝试在我的网站上实现自动完成功能.我在页面上有一个包含所有选项的html列表.

<div id="list"><ul><li>option1</li><li>option2</li><li>option3</li></ul></div>
Run Code Online (Sandbox Code Playgroud)

在我的javascript文件中,我使用HTML中的列表创建了数组:

  $(function () {
var lst_source = $("#list");
var lst_options = $("li", loc_source);

lst_options.each(function(){
// Creating my array here
    });
Run Code Online (Sandbox Code Playgroud)

有了这个,我试图在使用id ="list"标识的文本框上启用自动完成功能.我搜索了很多,但无法理解实现,所以它的工作原理.我不能在这里使用ajax,只能使用局部变量.

请指导我.

Suj*_*wal 6

这是来自jqueryUi示例本身:

// Set the array of results    
var countryList = ["Afghanistan", "Albania", "Algeria"/*... and so on*/];

// Set the autocomplete for the countries input
$("#countries").autocomplete({
    source: countryList
});
Run Code Online (Sandbox Code Playgroud)

HTML

<input id="countries">
Run Code Online (Sandbox Code Playgroud)