zoukankan      html  css  js  c++  java
  • 学员操作——制作秒表定时器

    点击开始按钮进行秒表计时
    点击暂停按钮可以停止计时
    点击重置按钮可以清零时间

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>计时器</title>
    <style>
    .wrap{
    text-align:center;
    }
    .btn{
    margin:10px 0;
    }
    </style>
    </head>
    <body>
    <div class="wrap">
    <input type="text" id="timetext" value="00时00分00秒000毫秒" readonly><br>
    <div class="btn">
    <button type="button" onclick="start()">开始</button>
    <button type="button" onclick="stop()">停止</button>
    <button type="button" onclick="Reset()">重置</button>
    </div>
    </body>
    </html>
    <script>
    var hour=0,minute=0,second=0;
    var millisecond=0;
    var int;
    function Reset(){
    window.clearInterval(int);
    millisecond=hour=minute=second=0;
    document.getElementById('timetext').value='00时00分00秒000毫秒';    //重置
    }
    function start(){                           //开始
    int=setInterval(timer,50);
    }
    function timer(){
    millisecond=millisecond+50;
    if(millisecond>=1000){
    millisecond=0;
    second=second+1;
    }
    if(second>=60){
    second=0;
    minute=minute+1;
    }
    if(minute>=60){
    minute=0;
    hour=hour+1;
    }
    document.getElementById('timetext').value=hour+''+minute+''+second+''+millisecond+'毫秒';
    }
    function stop(){   //清零
    window.clearInterval(int);
    }
    </script>
  • 相关阅读:
    whereis which type find
    souce and bash 的区别
    systemctl daemon-reload
    linux /etc/profile bashrc bash_profile
    ulimt 和 sysctl
    MySQL 问题总结
    asyncio
    Linux 中 MySQL 操作
    总结一波 Redis 面试题
    os 模块 和 re 模块
  • 原文地址:https://www.cnblogs.com/304979850w/p/13154598.html
Copyright © 2011-2022 走看看