如何使用 Yarp 的 jQuery timeago 插件与 getjson&.html
我尝试了一些方法,但没有机会: http://timeago.yarp.com/
$(function() {
$('abbr.timeago').timeago();
$('.more').click(function() {
$.getJSON('http://127.0.0.1:9987/test/c.php?callback=?', function(datas){
$.each(datas, function(i, data) {
$('.fdiv2 .fdtl').html('<abbr class="timeago"></abbr');
});
});
$('.fdiv2 .fdtl').slideToggle(1000);
});
});
I tried some ways but no chance: http://timeago.yarp.com/
$(function() {
$('abbr.timeago').timeago();
$('.more').click(function() {
$.getJSON('http://127.0.0.1:9987/test/c.php?callback=?', function(datas){
$.each(datas, function(i, data) {
$('.fdiv2 .fdtl').html('<abbr class="timeago"></abbr');
});
});
$('.fdiv2 .fdtl').slideToggle(1000);
});
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您必须对最近插入的元素重新初始化
timeago
。还缓存可缓存的内容(无需多次调用$('.fdiv2 .fdtl')
):还要确保您确实应该迭代
datas
- 如果它数组中始终包含一个元素,您可以将$.each()
调用替换为var data = datas[0];
。如果它有更多元素并且您只想使用最后一个(看起来就是这种情况,但您没有向我们展示整个代码),那么您可以将其替换为var data = datas[datas .length-1];
(这会将最后一个元素分配给data
变量)。You have to re-initialize
timeago
on the recently inserted element. Also cache what is cachable (no need to invoke$('.fdiv2 .fdtl')
multiple times):Also make sure that you really should iterate through
datas
- if it always contains one element in the array, you can replace$.each()
call withvar data = datas[0];
. If it has more elements and you want to use only the last one (it looks like this is the case here, but you are not showing us the whole code), then you can replace it withvar data = datas[datas.length-1];
(which will assign last element todata
variable).尝试插入这行代码:
Try insert this line of code: