gpt4 book ai didi

javascript - 如何根据用户当前输入以编程方式访问匹配值列表 - jQuery 自动完成?

转载 作者:行者123 更新时间:2023-11-29 16:30:53 25 4
gpt4 key购买 nike

我有这个数组

["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" />

关于javascript - 如何根据用户当前输入以编程方式访问匹配值列表 - jQuery 自动完成?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57895122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com