javascript - 我的 typeahead,js 示例有什么问题?

标签 javascript jquery typeahead.js

我试图将我自己的 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 .

Here is the your updated jsFiddle demo

关于javascript - 我的 typeahead,js 示例有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17517844/

相关文章:

javascript - vuetifyjs : Adding only used icons to build

javascript - Angular 表单自定义验证器 null 返回不从表单中删除错误

java - PHP-Dojo 与 Java 的大型应用程序对比

javascript - Twitter Typeahead.js 和返回两个列表而不是一个列表的远程 URL

mysql - 如何使用 nodejs 和 ajax 使 typeahead 显示来自 mysql 的信息

javascript - Typeahead.js/Bloodhound 只显示一个结果

javascript - 主干 - 在模型更改时注销 View 事件

Javascript 替换功能不起作用

javascript - window.h 在 JavaScript 中意味着什么?

javascript - 导航菜单未在浏览器中呈现