从此位置的示例代码http://jqueryui.com/autocomplete/,我可以将它用于多个文本框吗?
例如我有tb1,tb2和tb3如何为这三个使用相同的脚本?
我是JQuery的新手,我很感激你的帮助。
谢谢!
答案 0 :(得分:4)
试试这个:
$( "#tags, #tags2, #tags3" ).autocomplete({
source: availableTags
});
答案 1 :(得分:4)
<script>
$(function(){
$(".auto-complete-tbx").autocomplete();
});
</script>
<input type="text" class="auto-complete-tbx" id="tb1" />
<input type="text" class="auto-complete-tbx" id="tb2" />
<input type="text" class="auto-complete-tbx" id="tb3" />
答案 2 :(得分:3)
使用“逗号”分隔多个输入并同时为它们提供选项,如
<script>
$(function() {
var availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"
];
$("#inputid1, #inputId2, #inputid3").autocomplete({
source: availableTags ;
}):
});
</script>