Javascript setInterval clearInterval Simple Example Not Working Explained?
问题 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 that is: var automessage; function turnON() //executed by onclick event A { var automessage = setInterval(function(){ something() }, 2000); } function turnOff() //executed by onclick event B { clearInterval(automessage); } function something() { //pulls instant messages } In this example, an end-user clicks a button to