码迷,mamicode.com
首页 > 其他好文 > 详细

简易秒表

时间:2016-11-15 00:26:11      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:文档   type   tle   标题   text   har   rip   title   char   

<!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 = 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="开始" id="btn1"/>
<input type="button" value="暂停" id="btn2"/>
</body>
</html>

简易秒表

标签:文档   type   tle   标题   text   har   rip   title   char   

原文地址:http://www.cnblogs.com/guolimin/p/6063841.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!