clearInterval is not clear



  • Why can't you turn the timer off?

    He just keeps working. I'm doing this because you have to start a timer in one function, and stop it in another. How's that?

    function refresh(e) {
        time = $.cookie("time");
    
    if(e != 'stop') {
        var c = setInterval(update, time+"000");
    } else {
        clearInterval(c);
    }
    

    }

    function chating() {
    if(time == null) {
    $.cookie("time", "5", {expires: 30, path: "/"});
    time = $.cookie("time");
    }

    refresh();
    

    }

    function setting() {
    refresh('stop');
    }



  • All because the revolving id timer is recorded in the local variable, it is therefore lost when the function is removed.

    It's worth keeping it global.

    var c;
    function refresh(e) {
        time = $.cookie("time");
    
    if(e != 'stop') {
        c = setInterval(update, time+"000");
    } else {
        clearInterval(c);
    }
    

    }


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2