[英]Can't get Twitter Typeahead to work in Bootstrap
This might be a noob issue, but I cannot figure out why this code is not working. 这可能是一个noob问题,但我无法弄清楚为什么这段代码不起作用。 FYI this is just a sample list of counties pulled from a state with just a few. 仅供参考,这只是一个从少数国家撤出的县的样本清单。 I pull the list from php based on earlier inputs, but that is not the issue, the list is fine, its autocomplete not working. 我根据之前的输入从php中提取列表,但这不是问题,列表很好,它的自动完成功能不起作用。
http://jsfiddle.net/s4wx9/ http://jsfiddle.net/s4wx9/
<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>
Just replace local
by source
in your javascript 只需在您的JavaScript中替换local
source
$("#county").typeahead({
source: ["Apache", "Cochise", "Coconino", "Gila", "Graham", "Greenlee", "La Paz", "Maricopa", "Mohave", "Navajo", "Pima", "Pinal", "Santa Cruz", "Yavapai", "Yuma"]
});
Local is used with the standalone Typeahead library. Local与独立的Typeahead库一起使用。
EDIT: Here's an updated jsfiddle: http://jsfiddle.net/s4wx9/1/ 编辑:这是一个更新的jsfiddle: http : //jsfiddle.net/s4wx9/1/
There are two problems 有两个问题
try 尝试
$("#county").typeahead({
source: ["Apache", "Cochise", "Coconino", "Gila", "Graham", "Greenlee", "La Paz", "Maricopa", "Mohave", "Navajo", "Pima", "Pinal", "Santa Cruz", "Yavapai", "Yuma"]
});
It works to me. 它对我有用。 Run this Code: 运行此代码:
<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>
Include:These above 包括:以上这些
jquery-2.1.1.min.js
bootstrap.min.css
bootstrap.min.js
You are done. 你完成了。 Thanks. 谢谢。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.