Appologies,jquery和autocomplete的新手。一直在搜索,但无法理解如何在网站上显示查询结果。
以下代码几乎是来自jquery自动完成网站http://jqueryui.com/autocomplete/的相同副本,最后修改了我的大脑拒绝掌握的内容......
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>jQuery UI Autocomplete - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jqueryui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
var availableTags = [
"ActionScript",
"Fortran",
"Groovy",
"Haskell",
"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>
<p>
The choice you selected is
<script>
???
</script>
</body>
</html>
任何提示/指针/解决方案阻止我绕圈子都会非常感激。
谢谢!
答案 0 :(得分:1)
您需要添加“select”事件处理程序以提取所选值。像这样:
$( "#tags" ).autocomplete({
source: availableTags,
select: function(event, ui) {
// console.log(ui.item);
$('p').text('You selected: ' + ui.item.value);
}
});