开发者

How do I use timeago.js?

开发者 https://www.devze.com 2023-02-09 17:38 出处:网络
I just started learning javascript for 2 weeks so I\'m pretty new to it. I can\'t get timeago from http://timeago.yarp.com/ to work! I don\'t understand this line of instruction:

I just started learning javascript for 2 weeks so I'm pretty new to it. I can't get timeago from http://timeago.yarp.com/ to work! I don't understand this line of instruction:

Now, let's attach it to your timestamps on DOM ready:

  jQuery(document).ready(function() {
  jQuery("abbr.timeago").timeago();
  });

Where are the "timesta开发者_C百科mps on DOM ready?" This is what I've came up with so far but it isn't working.

<html>
<head>
<script src="jquery.min.js" type="text/javascript"></script>
<script src="jquery.timeago.js" type="text/javascript"></script>
<script type="text/javascript">
jQuery(document).ready(function() {
  jQuery("abbr.timeago").timeago();
});
</script>
</head>
<body>
<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>
</body>
</html>

EDIT: I added the double quotes in the third script tag, but it still isn't working. The code

<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>

is taken from the example provided in http://timeago.yarp.com/

I'm suppose to see the date displayed as 2 years ago, but all I see is July 17, 2008. I'm testing this on WAMP.


As @Box9 pointed out in a comment (why do people put answers into comments?), your third <script> tag is missing a closing quote after "javascript", though I would expect HTML to be forgiving enough to overlook that.


Forgot to change the src in

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

to

<script src="jquery-1.4.4.min.js" type="text/javascript"></script>

A mistake worthy of a noob, guess I just have to learn from it :)

0

精彩评论

暂无评论...
验证码 换一张
取 消