【问题标题】:Uncaught TypeError: $(...).typed is not a function未捕获的 TypeError:$(...).typed 不是函数
【发布时间】:2018-03-13 05:53:05
【问题描述】:

我正在使用这个库https://github.com/mattboldt/typed.js/。我已经在正文代码的末尾添加了所有脚本文件,但我仍然在控制台中遇到错误。我的代码是:

  <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title>LUNA-NG</title>

        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="apple-touch-icon" href="apple-touch-icon.png">
         <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:200,400,700,900' rel='stylesheet" type="text/css">
        <link rel="stylesheet" href="css/bootstrap.min.css">
        <link href="https://fonts.googleapis.com/css?family=Montserrat:100,200,300,400,500,600,700,800,900" rel="stylesheet">
        <link rel="stylesheet" href="css/bootstrap-theme.min.css">
        <link rel="stylesheet" href="css/fontAwesome.css">
        <link rel="stylesheet" href="css/tooplate-style.css">
        <link rel="stylesheet" href="node_modules/typed.js/assets/demos.css">
    </head>

 <body>
<span class="typed"></span>
 <script src="js/vendor/jquery-1.11.2.min.js"></script>

        <script src="js/vendor/bootstrap.min.js"></script>

        <script src="js/plugins.js"></script>
        <script src="js/main.js"></script>
        <script src="node_modules/animejs/anime.min.js"></script>

        <!-- Google Analytics: change UA-XXXXX-X to be your site's ID. -->
        <script>
            (function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
            function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;
            e=o.createElement(i);r=o.getElementsByTagName(i)[0];
            e.src='//www.google-analytics.com/analytics.js';
            r.parentNode.insertBefore(e,r)}(window,document,'script','ga'));
            ga('create','UA-XXXXX-X','auto');ga('send','pageview');
        </script>

  <script type="text/javascript" src="jquery.interactive_3d.js"></script>

  <script src="node_modules/typed.js/lib/typed.js"></script>
    <script>
      $(function() {
  $(".typed").typed({
    strings: ["Typed.js is a jQuery plugin that types.", "Enter in any string,", "and watch it type at the speed you've set,", "backspace what it's typed,", "and begin a new sentence for however many strings you've set."],
    typeSpeed: 0
  });
});
        </script>

控制台:

Uncaught TypeError: $(...).typed is not a function
    at HTMLDocument.<anonymous> ((index):259)
    at j (jquery-1.11.2.min.js:2)
    at Object.fireWith [as resolveWith] (jquery-1.11.2.min.js:2)
    at Function.ready (jquery-1.11.2.min.js:2)
    at HTMLDocument.J (jquery-1.11.2.min.js:2)

非常感谢您在这方面的任何帮助。提前致谢。

【问题讨论】:

  • 看起来那个库不是 jQiery 插件。尝试使用 Typed 构造函数,就像您链接的仓库中的自述文件显示的那样。
  • @Paulpro codepen.io/merb/pen/yOwJjj 请看这段代码。
  • @waheedshah 它似乎 不再 是一个 jQuery 插件,从 v2 开始在没有 jQuery 的情况下被重写。 v1 的最后一次更新是v1.1.7

标签: javascript animation dom typed typed.js


【解决方案1】:

我正在为 typed.js 库使用 CDN。现在工作正常。即使我遇到错误,我也给出了正确的路径,所以我决定搬到 cdn。以下是我包含的脚本。感谢您的回答

<script src="https://cdnjs.cloudflare.com/ajax/libs/typed.js/1.1.1/typed.min.js"></script>

【讨论】:

    【解决方案2】:

    由于某些原因,可能会发生此错误: 1.你包含的jquery文件可能路径错误。 2. jquery 文件可能被多次包含在页面中。

    请检查以上几点,如果不起作用,我们可以进一步讨论。

    【讨论】:

    • $ 在这里有效
    • 问题在于包含类型化的包
    • 我在发布之前已经进行了更彻底的检查。我已经包含了 jquery 路径。它在文件中只包含一次,但我仍然面临这个问题。
    • console.log(Typed) 检查这个是返回字符串还是未定义
    • 我有一个'' 库,它需要 javascript 并且工作正常,但这个库不是工作。
    【解决方案3】:

    我认为正确的答案是从这个路径重新安装 typed.js。 我有同样的问题,我做了同样的解决方案,它现在对我有用 https://cdnjs.cloudflare.com/ajax/libs/typed.js/1.1.1/typed.min.js

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-15
      • 2020-04-15
      • 1970-01-01
      • 2020-10-05
      • 2019-09-15
      • 2018-12-21
      • 2018-11-12
      • 2022-01-18
      相关资源
      最近更新 更多