jQuery AutoComplete部件
描述
Widget AutoComplete 函数可以与JqueryUI中的小部件一起使用。自动完成小部件在您输入字段时提供建议。例如,如果输入Ja,则输出可为Java或JavaScript。
语法
使用自动完成的简单语法如下所示:
$( "#tags" ).autocomplete({
source: availableTags
});
示例
以下是一个简单的示例,展示了Autocomplete的用法 –
<!doctype html>
<html lang = "en">
<head>
<meta charset = "utf-8">
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel = "stylesheet"
href = "//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script type = "text/javascript"
src = "https://www.tutorialspoint.com/jquery/jquery-3.6.0.js">
</script>
<script type = "text/javascript"
src = "https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.3/jquery-ui.min.js">
</script>
<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"
];( "#tags" ).autocomplete({
source: availableTags
});
});
</script>
</head>
<body>
<div class = "ui-widget">
<label for = "tags">Tags: </label>
<input id = "tags">
</div>
</body>
</html>
这将产生以下结果−