简易秒表

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="智能社 - zhinengshe.com" />
<meta name="copyright" content="智能社 - zhinengshe.com" />
<title>智能社 - www.zhinengshe.com</title>

<script>

function addZero(n){
    if(n < 10){
      return "0" + n;
    } else {
      return "" + n;
    }
}

window.onload = function(){
    
    var aInput = document.getElementsByTagName("input");
    
    var timer = null;
    
    var bClick = false;//没有被点击
    var i = 0;
    // 秒转 分钟  秒
    aInput[1].onclick = function(){

        if(bClick == false){
            bClick =true;
            clearInterval(timer);
            timer=setInterval(function(){
                i++;
                aInput[0].value =addZero(parseInt(i/60))+ ":"+addZero(i%60);
            },100);
        }
    };
    

    aInput[aInput.length -1].onclick =function(){
        clearInterval(timer);
        bClick =false
    }
};



</script>
</head>

<body>

<input type="text" value="00:00" />
<input type="button" value="计时" />
<input type="button" value="暂停" />

</body>
</html>

原文地址:https://www.cnblogs.com/heboliufengjie/p/4478360.html