简单的jquery计数器

发布于 2024-11-28 15:05:32 字数 421 浏览 1 评论 0原文

大家好,我有一个非常简单的 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/

任何帮助

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.net/isimpledesign/mSQdp/

any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

戏舞 2024-12-05 15:05:32

要重置并重复,请将 count = 11; 放在 alert('done'); 之后。

要停止,请将 clearInterval(countdown); 放在 alert('done'); 之后。

To reset and repeat, put count = 11; after the alert('done');.

To stop, put clearInterval(countdown); after the alert('done');.

七禾 2024-12-05 15:05:32

试试这个

var count = 10;
  countdown = setInterval(function(){
    $("p.countdown").html(count + " seconds remaining!");
    count--;    
    if (count == 0) {
      count = 10;
    }

}, 1000);

Try this

var count = 10;
  countdown = setInterval(function(){
    $("p.countdown").html(count + " seconds remaining!");
    count--;    
    if (count == 0) {
      count = 10;
    }

}, 1000);
是你 2024-12-05 15:05:32
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);
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);
挽清梦 2024-12-05 15:05:32

就像这样:

if (count == 0)
  count = 11

您可能还想查看 jQuery 倒计时插件

Just like this:

if (count == 0)
  count = 11

You might also want to look at the jQuery countdown plugin

夜未央樱花落 2024-12-05 15:05:32
...
if (count == 0) {     
    alert('done');    
    count = 11;
}
...
...
if (count == 0) {     
    alert('done');    
    count = 11;
}
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文