今天用了点jquery ui的autocomplete插件,过程中可谓是遇到了许多问题,坎坎坷坷总算是成功了;具体的实现方法参见"http://jqueryui.com/"。这里面写的很详细,我只说两点注意事项:
1.注意jquery ui的版本,新的1.8+的实现方法和以前不同;
2.我们多数需要自己组装数据源,可以是本地数据源为本地js数组或本地的json对象;
3.形如
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
的数组可以直接用插件会自动在其中搜索;如果是形如
var projects = [
{
value: "jquery",
label: "jQuery",
desc: "the write less, do more, JavaScript library",
icon: "jquery_32x32.png"
},
{
value: "jquery-ui",
label: "jQuery UI",
desc: "the official user interface library for jQuery",
icon: "jqueryui_32x32.png"
},
{
value: "sizzlejs",
label: "Sizzle JS",
desc: "a pure-JavaScript CSS selector engine",
icon: "sizzlejs_32x32.png"
}
];
一定要label或者value,插件会根据这两个值搜索