我在jQuery中創建了一個倒計時,但我有一個問題。當計數到達01:00
它被卡住,而不是繼續上到00:59
爲0倒計時被卡在01:00
var start = $('#start');
var countMinutes = 2;
var timer;
start.on('click', function(event) {
event.preventDefault();
new Timer(function(val, countMinutes) {
timerMsg = (countMinutes >= 10 ? countMinutes : '0' + countMinutes) + ':' + (val >= 10 ? val : '0' + val);
time.text(timerMsg);
});
});
function Timer(callback, val, m) {
val = val || 59;
m = countMinutes;
timer = setInterval(function() {
callback(val, m);
if (val-- <= 0) {
m -= 1;
if (m < 1 && val <= 0) {
clearInterval(timer);
}
countMinutes = 0;
val += 60;
}
}, 1000);
}
我的html分鐘。
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1 id="timer"><span id="time">10:00</span></h1>
<a href="#" id="start">Start</a>
'如果(M <1 && VAL <= 0){''如果是M'分鐘會發生什麼? –
僅供參考:setInterval不準確。 – epascarello
爲什麼setInterval不準確? –