jQuery UI 实例 - 自动完成(Autocomplete)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI 实例</title>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.12.4.js"></script>
<script src="//code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<style>
.ui-autocomplete-category {
font-weight: bold;
padding: .2em .6em;
margin: .2em;
line-height: 1.5;
}
</style>
</head>
<body>
<p>
<label for="tags">标签:</label>
<input id="tags">
</p>
<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,
delay: 0
});
});
</script>
</body>
</html>
这段代码展示了如何使用jQuery UI库中的Autocomplete小部件来创建一个简单的标签自动完成输入框。用户可以输入一些字符来过滤可能的标签选项,这些选项是以数组的形式提供的。代码简洁,注释清晰,方便理解和学习。
评论已关闭