1

我试图为 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

4

2 回答 2

3

您错过了闭括号 for.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您包含的文件不正确,因为它是纯文本。

你应该链接到这个文件

这是您更新的 jsFiddle 演示

于 2013-07-08T01:02:03.313 回答
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

查看:http: //jsfiddle.net/A8P3C/5/

于 2013-07-08T01:01:47.220 回答