1 <h1>Counter</h1>2 <div id="display">0</div>3 <div id="buttons">4 <button id="start">START</button>5 <button id="stop">STOP</button>6 <button id="reset">RESET</button>7 </div>8 9 <script>10 var on = false;11 var c = 0;12 13 function SetNumber(n) {14 c=n;15 display.innerHTML = c;16 }17 18 var display = document.getElementById("display");19 document.getElementById("start").addEventListener("click", function(e) {20 on = true;21 }, true);22 document.getElementById("stop").addEventListener("click", function(e) {23 on = false;24 }, true);25 document.getElementById("reset").addEventListener("click", function(e) {26 SetNumber(0);27 }, true);28 29 setInterval(function() {30 if (!on) {31 return;32 }33 SetNumber(c++);34 }, 1500);35 36 37 </script>
Enlace
El enlace para compartir es: