Can I see if a timer is still running?

后端 未结 6 1832
青春惊慌失措
青春惊慌失措 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:24

    Set another variable Timer_Started = true with your timer. And also change the variable to false when the timer function is called:

    // set 'Timer_Started' when you setTimeout
    var Timer_Started = true;
    var Timer = setTimeout(DoThis,60000);
    
    function DoThis(){
    
       // function DoThis actions 
       //note that timer is done.
       Timer_Started = false;
    
    }
    
    function Check_If_My_Timer_Is_Done(){
    
       if(Timer_Started){
          alert("The timer must still be running.");
       }else{
          alert("The timer is DONE.");
       }
    
    }
    

提交回复
热议问题