admin管理员组文章数量:1401600
I have a value 011-04-29T14:55:33.000Z
this value gets push into a jQuery template. I used timeago to convert the date to elapsed time but after being written to the template it has no way of updating as more time passes.
How would I implement something that would automatically update?
I have a value 011-04-29T14:55:33.000Z
this value gets push into a jQuery template. I used timeago to convert the date to elapsed time but after being written to the template it has no way of updating as more time passes.
How would I implement something that would automatically update?
Share Improve this question edited Jan 24, 2016 at 13:30 Mosh Feu 29.4k18 gold badges93 silver badges141 bronze badges asked Apr 30, 2011 at 5:13 fancyfancy 51.5k64 gold badges158 silver badges230 bronze badges 1- Can you post your code on jsfiddle and provide a little more info on what you're trying to acplish? – Kevin Ennis Commented Apr 30, 2011 at 5:26
2 Answers
Reset to default 6Suppose you start with this (from the timeago homepage):
<abbr class="timeago" title="2008-07-17T09:24:17Z">July 17, 2008</abbr>
Now, the timeago plugin will change the title as it rewrites things. All you need to do is keep track of the timestamp elsewhere, put it back in the title
attribute, and rerun the plugin. Something like this:
<abbr
class="timeago"
title="2008-07-17T09:24:17Z"
data-ts="2008-07-17T09:24:17Z"
>July 17, 2008</abbr>
Will bee this:
<abbr
class="timeago"
title="July 17, 2008"
data-ts="2008-07-17T09:24:17Z"
>2 years ago</abbr>
And when you want to update it, just put data-ts
back in title
and rerun the plugin:
$('.timeago').each(function() {
var $this = $(this);
$this.attr('title', $this.data('ts'));
}).timeago();
If you're using an older jQuery, you might need to use $this.attr('data-ts')
in place of $this.data('ts')
.
I tried the above with no luck.and i found this. might be helpful.
https://mattbradley.github.io/livestampjs/
Here <span data-livestamp="your time goes here..."></span>
is enough.
Don't forget to add jquery.js
and moment.js
before livestamp.js
本文标签: javascriptHow do I use jQuery timeago to live updateStack Overflow
版权声明:本文标题:javascript - How do I use jQuery timeago to live update? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744240703a2596774.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论