Home >Web Front-end >JS Tutorial >Simple application method of timer
Here we implement the related operations of starting and pausing the timer
<script> var i = 0; var start; window.onload = function(){ document.getElementById("red").onclick = function(){ start = window.setInterval("time()",1000);//计时器 } document.getElementById("mom").onclick = function(){ window.clearInterval(start); } } function time(){ i++; document.getElementById("display").innerHTML = i; } </script> </head> <body> <p id="display"></p> <button id="red">掀起你的盖头来~~~~~</button> <button id="mom">啊,妈呀!!!</button> </body>
The above is the detailed content of Simple application method of timer. For more information, please follow other related articles on the PHP Chinese website!