Sunday 15 June 2014

javascript - Yes, another clearInterval Issue -


I'm officially stuck. I can not get the stopTimer () function to work properly, any help would be welcomed. Thanks!

  var counter; Function stopTimer () {window.clearInterval (counter); $ ('# QueryTimer') HTML ('') } Function startTimer () {var number = 60; Var counter = setInterval (function () {count = count - 1; if (count & lt; = 0) {window.clearInterval (counter); return;} $ ('# queryTimer'). Html ('Requery in:' + Gin + 'seconds.');}, 1000); } $ ('#start'). Click (function () {startTimer ();}); $ ('# Stop'). Click (function () {stopTimer ();});    

  var counter = setInterval (function () { < / Pre> 

It says, "A new variable is counter ". This means that the current variables are never changed, so in clear intervals You do not have the right identifier, you want to use the current variable:

  counter = setInterval (function () {   

No comments:

Post a Comment