[英]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>
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.