vartimerId;vartimerSec=3;window.onload=function(){timerId=setInterval('timer()',1000);}functiontimer(){varmin=Math.floor(timerSec/60)varsec=timerSec%60;varmsg=(min<10?"0"+min:min)+":"+(sec<10?"0"+sec:sec);timerSec--;if(timerSec<0){/* time End*/msg+="<br>Timer End!"clearInterval(timerId);}document.getElementById("timerTxt").innerHTML=msg;}
3) Full Source
<!DOCTYPE html><htmllang="ko"><head><metacharset="UTF-8"><title>타이머 샘플 소스</title></head><body><divid="timerTxt"></div><script type="text/javascript">vartimerId;vartimerSec=3;window.onload=function(){timerId=setInterval('timer()',1000);}functiontimer(){varmin=Math.floor(timerSec/60)varsec=timerSec%60;varmsg=(min<10?"0"+min:min)+":"+(sec<10?"0"+sec:sec);timerSec--;if(timerSec<0){/* time End*/msg+="<br>Timer End!"clearInterval(timerId);}document.getElementById("timerTxt").innerHTML=msg;}</script></body></html>