Javascript setInterval clearInterval Simple Example Not Working Explained?

前端 未结 3 797
星月不相逢
星月不相逢 2020-12-20 00:41

I have a very simple JS setInterval and clearInterval example that doesn\'t work. There has got to be an underlying reason why it does not work and I would like to know why

3条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-20 00:56

    automessage is declared twice - as a global variable and as a local variable. try:

    function turnON() //executed by onclick event A
    {
        automessage = setInterval(function(){ something() }, 2000);
    }
    

提交回复
热议问题