javascript计算器
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script type="text/javascript"> window.onload = function(){ var start = document.getElementById("start"); var stop = document.getElementById("stop"); start.onclick = function(){ 开始计时(); } stop.onclick = function(){ clearInterval(time); } } var i = 0; var time; function 开始计时(){ time = setTimeout(function(){ ++i; var div1 = document.getElementById("div1"); div1.innerHTML = "系统已经运行了"+i+"秒"; 开始计时() },1000); } </script> </head> <body> <div id="div1">系统已经运行了0秒</div> <input type="button" name="start" id="start" value="开始计时" /> <input type="button" name="stop" id="stop" value="结束计时" /> </body> </html>
js,计时器