• 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>

  • 相关阅读:
    C# SqlTransaction事务,先从后主
    去除HTML标记
    GIT拉取问题
    QQ音乐API
    解决UEditor编辑器禁用时点击文本编辑器会多加一个字符问题
    UEditor编辑器增加placeholder提示
    C# List去重及优化建议
    ref和out解析
    时间标准格式转换及数值的ToString的格式化
    没有被“怼”,顺利通过华为Android三面,看看面试官都问了我什么?
  • 原文地址:https://www.cnblogs.com/Sillynoob/p/4848642.html
Copyright © 2020-2023  润新知