首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我的typeahead有什么问题吗,js示例?

问我的typeahead有什么问题吗,js示例?
EN

Stack Overflow用户
提问于 2013-07-08 08:49:50
回答 2查看 4.1K关注 0票数 1

我试图为typeahead.js (http://twitter.github.io/typeahead.js/examples/)编写自己的示例,但由于某些原因,我无法使其正常工作。

小提琴:http://jsfiddle.net/A8P3C/

我已经包含了JSON,它应该是从源代码中的“本地”调用加载的。

代码语言:javascript
复制
<div class="example example-degrees">
<h2 class="example-name">Degrees</h2>

    <div class="demo">
        <input class="typeahead" type="text" placeholder="degrees">
     </div>

​

代码语言:javascript
复制
$(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"]
 });

我想我可以设置一个简单的例子,但是我不能让它工作

提亚

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-08 09:02:03

您遗漏了.ready及其回调函数的右括号。

代码语言:javascript
复制
$(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

票数 3
EN

Stack Overflow用户

发布于 2013-07-08 09:01:47

检查控制台是否有错误。无法加载添加到小提琴中的脚本:

代码语言:javascript
复制
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/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17517844

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档