基于我之前的问题(HERE)我已经更新了我的前一段时间代码块,它工作正常,间隔每10秒调用一次,但我面临另一个愚蠢的问题。 我的问题是我不知道如果加载正文后如何加载函数
我的代码(重要部分)
$(".elapsed_time").each(function() {
time_r = $(this).data('time_raw');
var self = $(this);
var inter = function() {self.html(time_ago(time_r));}
setInterval(inter, 10000);
});
答案 0 :(得分:0)
这可以通过将代码包装在以下代码中在jQuery中完成:
$(document).ready(function () {
//-- This code will run when the body is loaded
});
你也可以使用速记符号来完成同样的事情:
$(function () {
//-- This code will run when the body is loaded
});
编辑:凯文提出了一个很好的观点,这在技术上与真正的“身体负荷”事件不同。我解释你的问题的方式,你想等到所有元素都可用,然后再运行你的代码。