<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script> var i=0;//總秒數 var timer=null; window.onload=function(){ document.getElementById("start").onclick=function(){ timer=setInterval(function(){ i++; document.getElementById("sec").innerHTML=doubleNum(i%60); document.getElementById("min").innerHTML=doubleNum(parseInt(i/60)%60); document.getElementById("hour").innerHTML=doubleNum(parseInt(i/3600)); },1000); } document.getElementById("pause").onclick=function(){ clearInterval(timer); } document.getElementById("reast").onclick=function(){ clearInterval(timer); i=0; document.getElementById("sec").innerHTML="00"; document.getElementById("min").innerHTML="00"; document.getElementById("hour").innerHTML="00"; } } function doubleNum(n){ if(n<10){ return "0"+n; }else{ return n; } } </script> </head> <body> <div id="div1"> <span id ="hour">00</span> <span>:</span> <span id ="min">00</span> <span>:</span> <span id ="sec">00</span> <br /> <hr /> <button id="start">開始</button> <button id="pause">暫停</button> <button id="reast">復位</button> </div> </body> </html>