Can I see if a timer is still running?

后端 未结 6 1843
青春惊慌失措
青春惊慌失措 2020-12-02 19:34

Simple question here that I can\'t seem to find an answer for: Once a setTimeout is set, is there any way to see if it\'s still, well, set?

if (         


        
6条回答
  •  长情又很酷
    2020-12-02 20:12

    There is no need to check for an existing timer, just execute clearTimeout before starting the timer.

    var timer;
    //..
    var startTimer = function() {
      clearTimeout(timer);
      timer = setTimeout(DoThis, 6000);
    }
    

    This will clear any timer before starting a new instance.

提交回复
热议问题