javascript - Onclick reset setInterval -


<!doctype html> <html> <head> <script>  function timer(x) {     if (x == 1) {         //reset timer          }     var = 0;     var timer = setinterval(function() {          var x = document.getelementbyid("demo").innerhtml = i;         = + 1;      }, 500); }  </script> </head> <body>   <p id="demo">hello</p>  <button type="button" onclick="timer(0)">change</button>  <button type="button" onclick="timer(1)">reset</button>  </body> </html>  

i want reset timer onclick . e.g. if setintervaltime set 5 sec , 3 seconds elapsed ,after if on click on reset button should start gain 5 seconds.how this.

  1. keep return value of settimeout somewhere can again (currently storing in local variable, goes away when function ends)
  2. call cleartimeout(timer);
  3. call settimeout whatever arguments want again.

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -