这可能是一个noob问题,但我无法弄清楚为什么这段代码不起作用。仅供参考,这只是一个从少数国家撤出的县的样本清单。我根据之前的输入从php中提取列表,但这不是问题,列表很好,它的自动完成功能不起作用。
<div>Local County:
<input type="text" class="input-block-level required typeahead" id="county" name='county' placeholder="Local County" />
<div>
<script>
$("#county").typeahead({
local: ["Apache", "Cochise", "Coconino", "Gila", "Graham", "Greenlee", "La Paz", "Maricopa", "Mohave", "Navajo", "Pima", "Pinal", "Santa Cruz", "Yavapai", "Yuma"]
});
</script>
答案 0 :(得分:2)
只需在您的javascript中将local
替换为source
$("#county").typeahead({
source: ["Apache", "Cochise", "Coconino", "Gila", "Graham", "Greenlee", "La Paz", "Maricopa", "Mohave", "Navajo", "Pima", "Pinal", "Santa Cruz", "Yavapai", "Yuma"]
});
Local与独立的Typeahead库一起使用。
编辑:这是一个更新的jsfiddle:http://jsfiddle.net/s4wx9/1/
答案 1 :(得分:1)
有两个问题
试
$("#county").typeahead({
source: ["Apache", "Cochise", "Coconino", "Gila", "Graham", "Greenlee", "La Paz", "Maricopa", "Mohave", "Navajo", "Pima", "Pinal", "Santa Cruz", "Yavapai", "Yuma"]
});
演示:Fiddle
答案 2 :(得分:0)
对我有用。 运行此代码:
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.1/bootstrap3-typeahead.min.js"></script>
<div>Cnty:
<input type="text" class="input-block-level required typeahead" id="county" name='county' placeholder="Local County" />
<div>
<script>
$("#county").typeahead({
source: ["Apache", "Cochise", "Coconino", "Gila", "Graham", "Greenlee", "La Paz", "Maricopa", "Mohave", "Navajo", "Pima", "Pinal", "Santa Cruz", "Yavapai", "Yuma"]
});
</script>
包括:以上这些
jquery-2.1.1.min.js
bootstrap.min.css
bootstrap.min.js
您完成了。谢谢。