【问题标题】:Typed.js - Undefined is not a functionTyped.js - 未定义不是一个函数
【发布时间】:2015-03-16 03:19:30
【问题描述】:

我正在尝试使用 Typed.js 库,但它似乎不起作用。它在控制台中给了我以下错误消息:

 Uncaught TypeError: undefined is not a function

控制台中的引用是这一行:

 $("#typed").typed({

错误似乎表明我没有包含 jQuery,但我有。

<!-- TYPED -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="js/typed.js"></script>

<script>
$(function(){

    $("#typed").typed({
        strings: ["Typed.js is a <strong>jQuery</strong> plugin.", "It <em>types</em> out sentences.", "And then deletes them.", "Try it out!"],
        typeSpeed: 30,
        backDelay: 500,
        loop: false,
        contentType: 'html', // or text
        // defaults to false for infinite loop
        loopCount: false,
        callback: function(){ foo(); },
        resetCallback: function() { newTyped(); }
    });

    $(".reset").click(function(){
        $("#typed").typed('reset');
    });

});

function newTyped(){ /* A new typed object */ }
function foo(){ console.log("Callback"); }

html:

<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">
                <div class="post-heading">
                    <h1>Baresso og Starbucks</h1>
                    <h2 class="subheading element">Så mange kalorier smider de rundt</h2>
                    <h2 class="element" id="typed">hej</h2>
                    <span class="meta">Posted by <a href="https://www.linkedin.com/profile/view?id=176878997&trk=nav_responsive_tab_profile">Kristoffer Andreasen</a> on November 24, 2014</span>
                </div>

这可能真的很简单,但我现在无法弄清楚。 你能帮帮我吗?

【问题讨论】:

  • 你确定js/typed.js的路径正确吗?
  • 我解决了这个问题。 JQuery 也是稍后在页面上加载的。副本导致它在脚本之后加载。感谢您的帮助。

标签: jquery undefined typed


【解决方案1】:

要重现这种问题,我们可以

1) “删除”角脚本参考,或 2) 只需将它放在我们模块之后的非常“晚”的位置。

Try To Load scripts in the sequence below:-
app.Module
Controller
Interface
angular.js
angular.min.js
app.route

【讨论】:

    【解决方案2】:

    当我使用 cdn version("https://cdn.bootcss.com/typed.js/1.1.4/typed.min.js") 时,它工作正常。但是当我尝试从 github 下载 typed.js 时,它给出了同样的错误。

    为了解决这个问题,我访问了 cdn 链接并将页面复制到我的 typed.js 中。它解决了我的问题。

    【讨论】:

      猜你喜欢
      • 2015-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-19
      • 1970-01-01
      • 1970-01-01
      • 2018-01-14
      • 1970-01-01
      相关资源
      最近更新 更多