admin管理员组文章数量:1379395
Hi all i have got this really simple jquery counter
var count = 10;
countdown = setInterval(function(){
$("p.countdown").html(count + " seconds remaining!");
if (count == 0) {
alert('done');
}
count--;
}, 1000);
How can i make it reset after it gets to 0 instead of going into minus???? so it keep iterating.
/
any help
Hi all i have got this really simple jquery counter
var count = 10;
countdown = setInterval(function(){
$("p.countdown").html(count + " seconds remaining!");
if (count == 0) {
alert('done');
}
count--;
}, 1000);
How can i make it reset after it gets to 0 instead of going into minus???? so it keep iterating.
http://jsfiddle/isimpledesign/mSQdp/
any help
Share Improve this question edited Aug 10, 2011 at 13:42 Naftali 146k41 gold badges247 silver badges304 bronze badges asked Aug 10, 2011 at 13:39 DCHPDCHP 1,1316 gold badges30 silver badges54 bronze badges 05 Answers
Reset to default 3To reset and repeat, put count = 11;
after the alert('done');
.
To stop, put clearInterval(countdown);
after the alert('done');
.
Try this
var count = 10;
countdown = setInterval(function(){
$("p.countdown").html(count + " seconds remaining!");
count--;
if (count == 0) {
count = 10;
}
}, 1000);
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);
Just like this:
if (count == 0)
count = 11
You might also want to look at the jQuery countdown plugin
...
if (count == 0) {
alert('done');
count = 11;
}
...
本文标签: javascriptSimple jquery counterStack Overflow
版权声明:本文标题:javascript - Simple jquery counter - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744483811a2608327.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论