zoukankan      html  css  js  c++  java
  • js计时器

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>计时器</title>
    <script type="text/javascript">
    var t=0;
    var t1;
    //定义$函数获取id
    function $(id){
      return document.getElementById(id);
    }
    //开始计时
    function timeStart(){
      hour = parseInt(t / 3600);// 时
      min = parseInt(t / 60);// 分
      if(min>=60){
        min = min % 60;
      }
      lastsecs = t % 60; //秒
      if(lastsecs<10){lastsecs = '0' + lastsecs;}
      if(min<10){min = '0' + min;}
      if(hour<10){hour = '0' + hour;}
      //在输入框显示计时
      $('txt').value = hour + ":" + min + ":" + lastsecs;
      t = t + 1;
      t1 = setTimeout('timeStart()',1000)
      $('start').style.display = "none";
      $('stop').style.display = "";
    }
    //停止计时
    function timeStop(){
      clearTimeout(t1)
      $('start').style.display = "";
      $('stop').style.display = "none";
    }
    //清除
    function clearAll(){
      t=0;
      $('txt').value= "00:" + "00:" + "00";
      clearTimeout(t1);
      $('start').style.display ="";
      $('stop').style.display = "none";
    }
    </script>
    </head>
    <body>
    <p>点击“开始计时”按钮启动计时器开始进行计时,从 0 开始,点击“停止计时”按钮停止计时。</p>
    <form>
    <input type="text" id="txt" value="00:00:00" />
    <input type="button" value="开始计时" id="start" onClick="timeStart()" />
    <input type="button" value="停止计时" style="display:none" id="stop" onClick="timeStop()" />
    <input type="button" value="清除" onClick="clearAll()" />
    </form>
    </body>
    </html>

  • 相关阅读:
    Ftp、Ftps与Sftp之间的区别
    Previous Workflow Versions in Nintex Workflow
    Span<T>
    .NET Core 2.0及.NET Standard 2.0 Description
    Announcing Windows Template Studio in UWP
    安装.Net Standard 2.0, Impressive
    SQL 给视图赋权限
    Visual Studio for Mac中的ASP.NET Core
    How the Microsoft Bot Framework Changed Where My Friends and I Eat: Part 1
    用于Azure功能的Visual Studio 2017工具
  • 原文地址:https://www.cnblogs.com/Sillynoob/p/4848642.html
Copyright © 2011-2022 走看看