<input type="text" id="t1" value="00:00">
<div id="btn1">开始</div>
<div id="btn2">暂停</div>
<script>
window.onload = function() {
var Time = document.getElementById('t1');
var Btn = document.getElementById('btn1');
var Btn2 = document.getElementById('btn2');
var timer = null;
function Dou(n) {
return n < 10 ? '0' + n : '' + n;
}
var num = parseInt(Time.value);
var bSin = false;
Btn.onclick = function() {
if (bSin) {
return;
}
bSin = true;
/*暂停时间*/
clearInterval(timer);
function m(){
num++;
var iM = parseInt(num / 60);
var iS = num % 60;
Time.value = Dou(iM) + ':' + Dou(iS);
}
m();
/*过1000毫秒 执行一次 m函数*/
timer = setInterval(m,1000);
};
Btn2.onclick = function() {
/*暂停时间*/
clearInterval(timer);
bSin = false;
};
};
</script>