我一直试图让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>