我想用setTimeout每10秒重複一次函數。我的功能是:我的setTimeout不尊重延遲
dateInLive = function() {
crono = function(){
setTimeout(function() {
$('.datePoste').each(function(){
$(this).load('in_live.php','in_live='+$(this).attr('id'))
});
crono();
}
,10000);
}
crono();
}
但是,它確實是隨機的;有時在15s之後重複,有時在3s之後,有時在6s之後。
它看起來像你不小心叫了兩次crono()。嘗試從setTimeout中刪除crono()調用? – lifetimes 2013-03-26 15:51:06
看起來你可以使用'setInterval()'而不是'setTimeout()'來獲得更多的好處。 – 2013-03-26 15:51:36
@ user125697不,他在'setTimeout()'中調用它來重複該函數。相反,最好使用'setInteral()'。 – Antony 2013-03-26 15:51:37