<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript" src="js\typeahead.bundle.js"></script>
<script type="text/javascript">
$(document).ready(function(){
// Sonstructs the suggestion engine
var countries = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.whitespace,
queryTokenizer: Bloodhound.tokenizers.whitespace,
// The url points to a json file that contains an array of country names
prefetch: 'data/countries.json'
});
// Initializing the typeahead with remote dataset
$('.typeahead').typeahead(null, {
name: 'countries',
source: countries,
item: 4,
limit: 10 /* Specify maximum number of suggestions to be displayed */
});
});
</script>
以上是我的javascript,以下是我的HTML代码。当我运行脚本时,自动完成或过滤的项目不会出现在屏幕上。
<body>
<div class="bs-example">
<h2>Enter your country name</h2>
<input type="text" class="typeahead tt-query" autocomplete="off" spellcheck="false">
</div>
</body>
我认为脚本中的预取可能有问题。任何人都可以帮我这个..