我有了倒計時工作,我想阻止它爲0時,這裏是我的代碼如何停止倒計時
function countdown() {
// your code goes here
var count = $('.c').attr('id');
var timerId = setInterval(function() {
count--;
$('.c').text(count)
if (count == 0) {
$("#page").load("page.php");
$('#beforeloading').html('');
count = 60;
}
}, 1000);
}
你可以'clearInterval(intervalName)' – Keatinge
你真的從一個元素的'id'讓你的初始'count'? –
[在JavaScript中停止setInterval調用]的可能重複(https://stackoverflow.com/questions/109086/stop-setinterval-call-in-javascript) – evilReiko