setInterval()不起作用 [英] setInterval() not working
本文介绍了setInterval()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在code> setInterval()的1秒内运行一个函数,但这有点问题。我已经完成了此处所示的一切,但它不起作用。
I am trying to run a function at setInterval()
of "1 second", but it is a bit problematic. I have done everything as shown here but it doesn't work.
这是我的代码:
<script>
function test(db_time)
{
var c_db_time= db_time/1000;
var current_time = new Date().getTime()/1000;
return Math.round(current_time - c_db_time);
}
$(".elapsed_time").each(function() {
var time_r = $(this).data('time_raw');
var inter = $(this).html(time_ago(time_r));//parameter to function
setInterval(inter,1000)
});
</script>
错误是:未捕获的SyntaxError:意外的标识符
找到解决方案感谢@Bommox& @Satpal
Solution found thanks to @Bommox & @Satpal
$(".elapsed_time").each(function() {
var time_r = $(this).data('time_raw');
var self = $(this);
var inter = function() {self.html(time_ago(time_r));}
setInterval(inter, 1000);
});
推荐答案
如前所述,第一个参数应该是函数:
As said before, first argument should be the function:
var self = $(this);
var inter = function() {
self.html(time_ago(time_r));
}
setInterval(inter, 1000);
这篇关于setInterval()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文