我试图将我自己的 typeahead.js ( http://twitter.github.io/typeahead.js/examples/ ) 示例放在一起,但出于某种原因我无法让它工作。
fiddle :http://jsfiddle.net/A8P3C/
我包含了我的 JSON,它应该从源代码中的“本地”调用加载。
<div class="example example-degrees">
<h2 class="example-name">Degrees</h2>
<div class="demo">
<input class="typeahead" type="text" placeholder="degrees">
</div>
$(document).ready(function() {
$('.countries .typeahead').typeahead({
name: 'degrees',
local: ["Bachelor of Science","Bachelor of Science in Accounting","Bachelor of Science in Business","Bachelor of Science in Business\/Accounting","Bachelor of Science in Business\/Administration","Bachelor of Science in Business\/Communications","Bachelor of Science in Business\/e-Business","Bachelor of Science in Business\/Finance","Bachelor of Science in Business\/Global Business Management","Bachelor of Science in Business\/Green and Sustainable","Bachelor of Science in Business\/Green and Sustainable Enterprise Management","Bachelor of Science in Business\/Hospitality Management","Bachelor of Science in Business\/Human Resource Management"]
});
我以为我可以设置一个简单的例子,但我无法让它工作
TIA
最佳答案
您错过了 .ready
及其回调函数的右括号。
$(document).ready(function() {
$('.example-countries .typeahead').typeahead({
name: 'countries',
local: ["Bachelor of Science",
"Bachelor of Science in Accounting",
"Bachelor of Science in Business",
"Bachelor of Science in Business\/Accounting",
"Bachelor of Science in Business\/Administration",
"Bachelor of Science in Business\/Communications",
"Bachelor of Science in Business\/e-Business",
"Bachelor of Science in Business\/Finance",
"Bachelor of Science in Business\/Global Business Management",
"Bachelor of Science in Business\/Green and Sustainable",
"Bachelor of Science in Business\/Green and Sustainable Enterprise Management",
"Bachelor of Science in Business\/Hospitality Management",
"Bachelor of Science in Business\/Human Resource Management"]
}); // <-- add missing closing bracket for ready().
并且您包含的 typeahead.js
文件不正确,因为它是纯文本。
您应该链接到 this file .
关于javascript - 我的 typeahead,js 示例有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17517844/