Can clearInterval() be called inside setInterval()?

后端 未结 1 1111
不思量自难忘°
不思量自难忘° 2020-12-12 17:40
bigloop=setInterval(function () {
              var checked = $(\'#status_table tr [id^=\"monitor_\"]:checked\');
                if (checked.index()===-1 ||checked.         


        
相关标签:
1条回答
  • 2020-12-12 18:33

    Yes you can. You can even test it:

    var i = 0;
    var timer = setInterval(function() {
      console.log(++i);
      if (i === 5) clearInterval(timer);
      console.log('post-interval'); //this will still run after clearing
    }, 200);

    In this example, this timer clears when i reaches 5.

    0 讨论(0)
提交回复
热议问题