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"]
 });

簡単な例を設定できると思ったのですが、うまくいきません

ティア

4

2 に答える 2

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ファイルはプレーンテキストであるため、正しくありません。

このファイルにリンクする必要があります。

これが更新された 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 に答える