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>

  • 相关阅读:
    2.HTML案例二 头条页面
    1.HTML入门
    33.1.网络编程入门
    32.原子性
    【转】风控中的特征评价指标(一)——IV和WOE
    【转】Python调用C语言动态链接库
    基于蒙特卡洛树搜索(MCTS)的多维可加性指标的异常根因定位
    正则表达式全集
    基于ray的分布式机器学习(二)
    基于ray的分布式机器学习(一)
  • 原文地址:https://www.cnblogs.com/web-leader/p/4219533.html
Copyright © 2011-2022 走看看