我想在jQuery中創建一個計時器,我希望每秒更改一次span的值,但是這種延遲不起作用。循環內部的jQuery延遲
function startTimer(daysRemain,hoursRemain,minutesRemain,secondsRemain){
while(secondsRemain < 60){
secondsRemain++;
$("span.secondRemain").delay(1000).text(secondsRemain); //change value of seconds each one second
// I try this way too!
/* setTimeout(function(){
$("span.secondRemain").text(secondsRemain);
},1000);*/
}
嗯,你是對的,但我試過的setTimeout太也不起作用。 – palAlaa
'setTimeout'只會調用一次。您可以在初始的'setTimeout'中再次調用'setTimeout'或者使用'setInterval''參見我的編輯以獲取基本的定時器示例。 – Trevor