大家好我有这个非常简单的jquery计数器
var count = 10;
countdown = setInterval(function(){
$("p.countdown").html(count + " seconds remaining!");
if (count == 0) {
alert('done');
}
count--;
}, 1000);
如何在它变为0后重置而不是进入减号????所以它不断迭代。
http://jsfiddle.net/isimpledesign/mSQdp/
任何帮助
答案 0 :(得分:3)
要重置并重复,请将count = 11;
放在alert('done');
之后。
要停止,请将clearInterval(countdown);
放在alert('done');
之后。
答案 1 :(得分:1)
var count = 10,
countdown = setInterval(function () {
$("p.countdown").html(count + " seconds remaining!");
if (count == 0) {
count = 11; //since it will be reduced right after this
//clearInterval(countdown); <-- use this if you want to stop
alert('done');
}
count--;
}, 1000);
答案 2 :(得分:1)
试试这个
var count = 10;
countdown = setInterval(function(){
$("p.countdown").html(count + " seconds remaining!");
count--;
if (count == 0) {
count = 10;
}
}, 1000);
答案 3 :(得分:0)
答案 4 :(得分:0)
...
if (count == 0) {
alert('done');
count = 11;
}
...