【发布时间】:2015-07-31 09:44:28
【问题描述】:
我已经尝试让 typeahead.js 工作 2 天了,但我拒绝相信它应该这么难。到目前为止,没有一个示例有效,我一直在努力找出问题所在。
首先,我的 typeahead.bundle.js 文件是从这个存储库下载的:
https://github.com/twitter/typeahead.js/tree/master/dist
我的代码如下所示:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Typeahead example</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css">
</head>
<body>
<input id="search"/>
<!-- jQuery -->
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="http://code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<!-- Latest compiled and minified Bootstrap -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<!-- Latest Typeahead.js -->
<script src="typeahead.bundle.js"></script>
<script type="text/javascript">
var colors = ["red", "blue", "green", "yellow", "brown", "black"];
$(document).ready(function() {
$('#search').typeahead({source: colors});
})
</script>
</body>
</html>
请帮我解决这个问题。
编辑:根据 sakir 的回答,我现在更改了我的 Javascript 代码以适应版本 10 的语法,但它仍然不会显示任何建议:
<script type="text/javascript">
var colors = ["red", "blue", "green", "yellow", "brown", "black"];
$(document).ready(function() {
$('#search').typeahead({
highlight: true,
hint: false
}, colors);
});
</script>
【问题讨论】:
-
@sakir 没有错误,建议下拉菜单不会显示。
标签: javascript jquery typeahead.js typeahead twitter-typeahead