我如何使用timeago.js?

时间:2011-02-11 04:17:42

标签: javascript jquery

我刚刚开始学习javascript 2周,所以我对它很陌生。我无法从http://timeago.yarp.com/获得时间表来工作!我不明白这条指令:

现在,让我们将它附加到DOM准备好的时间戳上:

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

“DOM准备好的时间戳”在哪里?这是我到目前为止所提出的,但它无法正常工作。

<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>

编辑:我在第三个脚本代码中添加了双引号,但它仍无效。代码

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

取自http://timeago.yarp.com/

中提供的示例

我想看到日期显示为2年前,但我看到的只是2008年7月17日。我正在WAMP上测试。

2 个答案:

答案 0 :(得分:2)

忘了改变

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

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

一个值得一个菜鸟的错误,我想我只需要从中学习:)

答案 1 :(得分:1)

正如@ Box9在评论中指出的那样(为什么人们将答案放入评论中?),你的第三个<script>标签在“javascript”之后缺少一个结束语,尽管我希望HTML能够宽容到忽略了这一点。