0
我不斷收到「倒計時沒有定義」。我如何解決這個問題?JavaScript的「倒計時」沒有與這條線</p> <pre><code>var timeout = setTimeout('countdown()',1000); </code></pre> <p>它應該循環的<code>function countdown()</code>每秒定義的錯誤
function countdown() {
var until = $('.time-elapsed').attr('data-time');
var nextmonth = new Date(until);
var now = new Date();
var timeDiff = nextmonth.getTime() - now.getTime();
if(timeDiff <=0) {
var nextmonth = new Date(until);
}
var seconds = Math.floor(timeDiff/1000);
var minutes = Math.floor(seconds/60);
var hours = Math.floor(minutes/60);
var days = Math.floor(hours/24);
hours%=24;
minutes%=60;
seconds%=60;
$('.time-elapsed').find('ul:eq(0)').find('li:eq(1)').html(days);
$('.time-elapsed').find('ul:eq(1)').find('li:eq(1)').html(hours);
$('.time-elapsed').find('ul:eq(2)').find('li:eq(1)').html(minutes);
$('.time-elapsed').find('ul:eq(3)').find('li:eq(1)').html(seconds);
var timeout = setTimeout('countdown()',1000);
}
我不會去「永遠」...... – Basic