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

    setInterval(function(){},time);

    每隔几秒要执行一个动作函数时就需要一个计时器。

    倒计时:(基于jquery)

        <script type="text/javascript">
                var intDiff = parseInt(300000);//定义总共要倒计时多少秒

                function time(){

                      var day=0;

                      var hour=0;

                      var second=0;

                      var minute=0;

                      if(intDiff>0){

                        day = Math.floor(intDiff / (60 * 60 * 24));
                        hour = Math.floor(intDiff / (60 * 60)) - (day * 24);
                        minute = Math.floor(intDiff / 60) - (day * 24 * 60) - (hour * 60);
                        second = Math.floor(intDiff) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60);
                        
                      }


                    $('#day').html(day+"天");
                    $('#hour').html(hour+'时');
                    $('#minute').html(minute+'分');
                    $('#second').html(second+'秒');

                        intDiff--;


                      if(minute<9) minute="0"+minute;

                      if(second<9) second="0"+second;

                }

                $(function(){

                    time();//页面加载时先调用函数再去调用定时器。
                    setInterval(time,1000);

                });
                </script>

        <body>
                <div style="float:left;margin-right:10px;" id="day"></div>
                <div style="float:left;margin-right:10px;" id="hour"></div>
                <div style="float:left;margin-right:10px;" id="minute"></div>
                <div style="float:left;margin-right:10px;" id="second"></div>
            </body>

  • 相关阅读:
    牛客小白月赛21
    牛客小白月赛21
    CodeForces 1333-C Eugene and an array(子区间和为0、前缀和)
    页面大小、页表项、虚拟地址和物理地址之间的关系(转)
    001-Paint_FreePythonGames项目代码详解(每行都有注释!!!)
    第17讲~第19讲:函数:python的乐高积木
    第16讲:序列!序列!
    第15讲:字符串格式化
    练习23--字符串、字节和编码
    第14讲:字符串--各种奇葩内置方法
  • 原文地址:https://www.cnblogs.com/web-leader/p/4219533.html
Copyright © 2011-2022 走看看