我试图为typeahead.js(http://twitter.github.io/typeahead.js/examples/)组合我自己的例子,由于某种原因我无法让它工作。
小提琴: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
答案 0 :(得分:3)
您错过了.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。
答案 1 :(得分:1)
检查控制台是否有错误。您添加到小提琴的脚本无法加载:
Refused to execute script from 'https://raw.github.com/twitter/typeahead.js/master/src/typeahead.js' because its MIME type ('text/plain') is not executable, and strict MIME type checking is enabled.
所以改成它:http://twitter.github.io/typeahead.js/releases/latest/typeahead.js