return FALSE; $r = well_tag_thread__update(array('id' => $id), $update); return $r; } function well_tag_thread_find($tagid, $page, $pagesize) { $arr = well_tag_thread__find(array('tagid' => $tagid), array('id' => -1), $page, $pagesize); return $arr; } function well_tag_thread_find_by_tid($tid, $page, $pagesize) { $arr = well_tag_thread__find(array('tid' => $tid), array(), $page, $pagesize); return $arr; } ?>javascript - Simple jquery counter - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Simple jquery counter - Stack Overflow

programmeradmin2浏览0评论

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 0
Add a ment  | 

5 Answers 5

Reset to default 3

To 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;
}
...
发布评论

评论列表(0)

  1. 暂无评论