我很遗憾再次问这个问题。我正在尝试在我的网站上实现自动完成。我在页面上有一个 html 列表,其中包含所有选项。
<div id="list"><ul><li>option1</li><li>option2</li><li>option3</li></ul></div>
在我的 javascript 文件中,我使用 HTML 中的列表创建了数组:
$(function () {
var lst_source = $("#list");
var lst_options = $("li", loc_source);
lst_options.each(function(){
// Creating my array here
});
通过这个,我尝试在用 id=“list”标识的文本框中启用自动完成功能。 我进行了很多搜索,但无法理解其实现,因此它可以工作。我这里不能使用ajax,只能使用局部变量。
请指导我。
最佳答案
这来自 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
});
HTML
<input id="countries">
关于javascript - 使用jquery自动完成而不使用ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9938805/