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

    页面脚本代码:

     <script type="text/javascript">


            //timer操作函数
            var CallTimeLen = "0";
            var timestart = null;
            var timer = null;

            //重新计时
            function Reset() {

                timestart = new Date();
                document.getElementById("showTime").innerHTML = "00:00";

            }
            //计时 开始
            function StartCal() {

                var timeend = new Date();
                var timedifference = timeend.getTime() - timestart.getTime();
                timeend.setTime(timedifference);
                var minutes_passed = timeend.getMinutes();
                if (minutes_passed < 10) {
                    minutes_passed = "0" + minutes_passed;
                }
                var seconds_passed = timeend.getSeconds();
                if (seconds_passed < 10) {
                    seconds_passed = "0" + seconds_passed;
                }

                document.getElementById("showTime").innerHTML = minutes_passed + ":" + seconds_passed;

     

                window.timer = window.setTimeout("StartCal();", 1000);
             

            }
           
        </script>

     

    aspx页面:

        <span id="showTime" style="color: Red">00:00</span>

     

    aspx.cs代码:

         只需在需要调用计时函数的事件中加入这句代码就万事俱备,只欠东风:

          ScriptManager.RegisterStartupScript(this, this.GetType(), "js", " var timestart = new Date(); StartCal();", true);

         在需要调用重新计时函数的事件中加入这句代码就大功告成:

          ScriptManager.RegisterStartupScript(this, this.GetType(), "js", " Reset(); StartCal();", true);

     

  • 相关阅读:
    Django_rest_framework
    Django之FBV / CBV和中间件
    数据库之MySQL补充
    数据库之Python操作MySQL
    数据库之MySQL进阶
    数据库之初识MySQL
    2-3、配置Filebeat
    2-2、安装Filebeat
    2-1、FileBeat入门
    5、Filebeat工作原理
  • 原文地址:https://www.cnblogs.com/xiaohui1990/p/3431032.html
Copyright © 2011-2022 走看看