简体   繁体   English

获取“未捕获的TypeError:$(...)。timeago不是函数”

[英]Getting 'Uncaught TypeError: $(…).timeago is not a function'

To calculate the relative time of a post I'm using jquery-timeago library. 为了计算帖子的相对时间,我正在使用jquery-timeago库。 Here is the JavaScript code which I need to place in the HTML page 这是我需要在HTML页面中放置的JavaScript代码

<script type="text/javascript">
   jQuery(document).ready(function() {
     $("abbr.timeago").timeago();
   });
</script>

I have also included Jquery 我也包括了Jquery

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>

Im still getting the error as 我仍然收到错误

在此处输入图片说明

How do I resolve this error? 如何解决此错误? There are already few questions such as this on Stack Overflow but none of them could resolve my issue. 关于Stack Overflow的问题已经很少了,但是没有一个可以解决我的问题。

EDIT: 编辑:

Here's the head part of the HTML page 这是HTML页面的头部

 <html>

<head>
    {% for ud in userdata %}
    <title>{{ud.fullname}} </title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href='https://fonts.googleapis.com/css?family=Open+Sans:300,400,700' rel='stylesheet' type='text/css'>
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>


    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.4.3/jquery.timeago.js" type="text/javascript"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css">

    <script type="text/javascript">
    jQuery(document).ready(function() {
        $("abbr.timeago").timeago();
    });
    </script>

</head>

Here's a fiddle. 这是一个小提琴。 But it works fine. 但这很好。 DEMO DEMO

EDIT : The issue has been resolved by making changes in the below way! 编辑:通过以下方式进行更改已解决了该问题!

<script type="text/javascript">
    var $j = jQuery.noConflict();
    $j(document).ready(function() {
        $j("abbr.timeago").timeago();
    });
    </script>

replace your current CDN with the below one and try. 将您当前的CDN替换为下面的CDN,然后尝试。

https://cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.4.3/jquery.timeago.js https://cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.4.3/jquery.timeago.js

在jquery.min.js之后添加

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery-timeago/1.4.3/jquery.timeago.min.js"></script>

Check this fiddle now Fiddle 现在检查这个小提琴

<abbr class="timeago" title="2011-12-17T09:24:17Z">December 17, 2011</abbr>
 jQuery(document).ready(function () {
   $("abbr.timeago").timeago();
 });

Place your code properly. 正确放置您的代码。 Then it will start working. 然后它将开始工作。

CDN CDN

Use the CDN provided by Shussain 使用Shussain提供的CDN

I had related issue, as per above in this exact case it was solved with Shussain user's comment: 我有相关的问题,按照上述在这个确切的情况下,已通过Shussain用户的评论解决了:

$j = jQuery.noConflict(); $j(document).ready(function() { $j("abbr.timeago").timeago(); }); 

But I have solved issue with replacing document ready as per below: 但是我已经解决了替换文档的问题,如下所示:

  (function ($) {
      "use strict"; 
      // Your js code

      });
    })(jQuery);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 获取“未捕获的TypeError:$(...)。dialog不是函数” - Getting “Uncaught TypeError: $(…).dialog is not a function” Jquery-timeago未捕获的TypeError:无法读取未定义的属性“替换” - Jquery-timeago Uncaught TypeError: Cannot read property 'replace' of undefined 获取未捕获的TypeError:在JSFiddle中undefined不是函数 - Getting an Uncaught TypeError: undefined is not a function in JSFiddle 获取错误未捕获TypeError:string不是函数 - Getting error Uncaught TypeError: string is not a function 误捕获TypeError:***最近几天不是函数 - Getting Uncaught TypeError: *** is not a function in recent days 视频库得到 Uncaught TypeError: $(...).lightGallery is not a function - video gallery getting Uncaught TypeError: $(...).lightGallery is not a function 使用 webpack 获取“未捕获的类型错误:$(...).tablesorter is not a function” - Getting 'Uncaught TypeError: $(...).tablesorter is not a function' using webpack 出现js错误未捕获的TypeError:roundScore不是函数 - getting js error Uncaught TypeError: roundScore is not a function 使用Javascript IFFE不能获得Uncaught TypeError不是函数 - With a Javascript IFFE getting a Uncaught TypeError is not a function 遇到未捕获的ReferenceError:未定义_和未捕获的TypeError:未定义不是函数 - Getting uncaught ReferenceError: _ is not defined and Uncaught TypeError: undefined is not a function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM