<div id="countdown">
<span>02</span>分钟<span>30</span>秒
<input type="button" value="启动">
</div>
window.onload = function(){
var aSpan = document.getElementsByTagName("span");
var oInput = document.getElementsByTagName("input")[0];
var num = parseInt(aSpan[0].innerHTML)*60 + parseInt(aSpan[1].innerHTML);
var timer;
oInput.onclick = function(){
timer = setInterval(function(){
num--;
aSpan[0].innerHTML = toTwo(parseInt(num/60));
aSpan[1].innerHTML = toTwo(parseInt(num%60));
if(num <= 0){
clearInterval(timer);
alert("倒计时结束!")
};
},1000);
};
function toTwo(n){
return n<10 ? "0"+n : n;
};
};