jQuery的:获取.timeago()上班后DOM准备装元素(阿贾克斯) [英] jQuery: Get .timeago() to work on elements loaded after DOM ready (Ajax)

查看:119
本文介绍了jQuery的:获取.timeago()上班后DOM准备装元素(阿贾克斯)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用pageless1引发的年纪大了,时间戳内容的AJAX加载到页面上的最后,我需要 .timeago() 作用在这些新加载的日期。它的工作原理上加载的第一次在页​​面到达的内容,而不是通过Ajax加载的内容后。

Using pageless1 to trigger an ajax load of older, timestamped content onto the end of the page, I need .timeago() to act upon those newly loaded dates. It works on the content loaded the first time you arrive at the page, but not the content loaded via Ajax later.

谢谢!

推荐答案

有关运行的插件的(东西不是事件处理程序的基础),你仍然可以使用的 .livequery()插件,像这样的:

For running plugins (things not event handler based) you can still use the .livequery() plugin, like this:

$('.selector').livequery(function() {
  $(this).timeago();
});

如果它是一个事件处理程序, .live() .delegate() 工作,或者如果它是一个插件,你也可以运行在加载的内容的插件,例如:

If it's an event handler, .live() or .delegate() works, or if it's a plugin you can also run the plugins on loaded content, for example:

$.ajax({
  //options...
  success: function(data) {
    //do stuff
    $('.selector', data).timeago();
  }
});

这需要运行在选择的插件,但是的只有的该回来在Ajax响应,通过使用的 $(选择,[背景])

This runs the plugin on that selector, but only for elements that came back in that AJAX response, by using the context argument of $(selector, [context]).

这篇关于jQuery的:获取.timeago()上班后DOM准备装元素(阿贾克斯)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆