如何根据用户当前输入以编程方式访问匹配值列表 - jQuery 自动完成?
How to access a list of matched value programmatically base on user current input - jQuery Autocomplete?
我有这个数组
["ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"]
我在这里复制了它:https://jsfiddle.net/bheng/Lsubhxmv/
当我输入 "P"
- 我看到这个列表
预期结果
console.log(matchedValues), I should see ['ActionScript','AppleScript','Asp','Lisp','Perl','PHP','Python']
我一输入 "Py"
只有一个出现
预期结果
console.log(matchedValues), I should see ['Python']
我需要根据用户当前输入以编程方式访问 匹配 值的列表。
您可以使用自动完成的 response
事件来检索过滤后的值:
$(".search").autocomplete({
source: ["ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang"
// other values...
],
response: function(e, ui) {
console.log(ui);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
<input type="text" class="search" />
我有这个数组
["ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang",
"Fortran",
"Groovy",
"Haskell",
"Java",
"JavaScript",
"Lisp",
"Perl",
"PHP",
"Python",
"Ruby",
"Scala",
"Scheme"]
我在这里复制了它:https://jsfiddle.net/bheng/Lsubhxmv/
当我输入 "P"
- 我看到这个列表
预期结果
console.log(matchedValues), I should see ['ActionScript','AppleScript','Asp','Lisp','Perl','PHP','Python']
我一输入 "Py"
只有一个出现
预期结果
console.log(matchedValues), I should see ['Python']
我需要根据用户当前输入以编程方式访问 匹配 值的列表。
您可以使用自动完成的 response
事件来检索过滤后的值:
$(".search").autocomplete({
source: ["ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
"Clojure",
"COBOL",
"ColdFusion",
"Erlang"
// other values...
],
response: function(e, ui) {
console.log(ui);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="//code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<link rel="stylesheet" type="text/css" href="//code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css">
<input type="text" class="search" />