首页 > 代码库 > 简易秒表
简易秒表
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
function addZero(n){
if(n < 10){
return ‘0‘ + n;
}else{
return ‘‘ + n;
}
}
window.onload = function(){
var oTxt = document.getElementById(‘txt‘);
var oBtn1 = document.getElementById(‘btn1‘);
var oBtn2 = document.getElementById(‘btn2‘);
var count = 0;
var timer = null;
oBtn1.onclick = function(){
clearInterval(timer);
timer = setInterval(function(){
count++;
oTxt.value = http://www.mamicode.com/addZero(parseInt(count/60)) + ‘:‘ + addZero(count%60);
},100);
}
oBtn2.onclick = function(){
clearInterval(timer);
}
}
</script>
</head>
<body>
<input type="text" value="" id="txt"/>
<input type="button" value="http://www.mamicode.com/开始" id="btn1"/>
<input type="button" value="http://www.mamicode.com/暂停" id="btn2"/>
</body>
</html>
简易秒表