Javascript 使用.load生成的内容的jQuery timeago
我正在使用来自的jQuery timeago插件 它在页面加载时工作得很好,但我使用Javascript 使用.load生成的内容的jQuery timeago,javascript,jquery,ajax,Javascript,Jquery,Ajax,我正在使用来自的jQuery timeago插件 它在页面加载时工作得很好,但我使用.load在模式窗口中生成了一些内容,而且似乎对它没有影响 要在一段时间前初始化,我有: $(document).ready(function() { $('time.timeago').timeago(); }); 这是我用来在模式中加载内容的jQuery: $(document).ready(function () { // on click, serialize all form ele
.load
在模式窗口中生成了一些内容,而且似乎对它没有影响
要在一段时间前初始化,我有:
$(document).ready(function() {
$('time.timeago').timeago();
});
这是我用来在模式中加载内容的jQuery:
$(document).ready(function () {
// on click, serialize all form elements and insert/update database
$('.comment').click(function (e) {
e.preventDefault();
var $this = $(this);
var csrf = $('input[name=csrf_gpin]').val();
var pin_id = $this.closest('.grid-box').attr('data-id');
$('input[name=comment_pin_id]').val(pin_id);
$("#modal-comment").reveal();
// load all comments associated with pin
$("#comments").load('/comment/pin', { 'csrf_gpin' : csrf, 'pin_id' : pin_id });
});
});
加载内容中的HTML为:
<time class="timeago" datetime="2012-11-19T20:35:14+01:00" title="November 19, 2012">2 days ago</time>
2天前
如何重新初始化timeago,使其能够处理生成的内容?加载完成后,尝试初始化
timeago
:
$("#comments").load('/comment/pin',
{ 'csrf_gpin' : csrf, 'pin_id' : pin_id },
function(){ //A callback function that is executed when the request completes
$(this).find('time.timeago').timeago();
});
加载完成后,尝试初始化
timeago
:
$("#comments").load('/comment/pin',
{ 'csrf_gpin' : csrf, 'pin_id' : pin_id },
function(){ //A callback function that is executed when the request completes
$(this).find('time.timeago').timeago();
});
完美,正是我所需要的!完美,正是我所需要的!