zoukankan      html  css  js  c++  java
  • Javascript倒计时源码.(时.分.秒)

    随便写写!闲着无聊!代码如有bug之处欢迎阁下强力拍砖!

    JS CODE

    <script type="text/javascript" language="javascript">
    //总时间,已分为单位
    var time = 100;

    //小时
    var h = parseInt(time / 60) > 0 ? parseInt(time / 60) : 0;

    //
    var m = time % 60;

    //
    var s = 60;

    //输出到当前Script的Dom位置
    document.write('<span>剩余<font id="f_hh">' + h + '</font>小时<font id="f_mm">' + m + '</font>分<font id="f_ss">' + s + '</font>秒</span>');

    //开始执行倒计时
    var timeInterval = setInterval(function () {

    //如果时、分、秒都为0时将停止当前的倒计时
    if (h == 0 && m == 0 && s == 0) { clearInterval(timeInterval); return; }

    //当秒走到0时,再次为60秒
    if (s == 0) { s = 60; }

    if (s == 60) {

    //每次当秒走到60秒时,分钟减一
    m -= 1;

    //当分等于0时并且小时还多余1个小时的时候进里面看看
    if (m == 0 && h > 0) {

    //小时减一
    h -= 1;

    //分钟自动默认为60分
    m = 60;

    //秒自动默认为60秒
    s = 60;
    }
    }

    //秒继续跳动,减一
    s -= 1;

    //小时赋值
    document.getElementById('f_hh').innerHTML = h;

    //分钟赋值
    document.getElementById('f_mm').innerHTML = m;

    //秒赋值
    document.getElementById('f_ss').innerHTML = s;

    },
    1000);
    </script>

    HTML CODE

    <html>
    <head>
    <title>Date Demo</title>
    </head>
    <body>
    <script type="text/javascript" language="javascript">
    //总时间,已分为单位
    var time = 100;

    //小时
    var h = parseInt(time / 60) > 0 ? parseInt(time / 60) : 0;

    //
    var m = time % 60;

    //
    var s = 60;

    //输出到当前Script的Dom位置
    document.write('<span>剩余<font id="f_hh">' + h + '</font>小时<font id="f_mm">' + m + '</font>分<font id="f_ss">' + s + '</font>秒</span>');

    //开始执行倒计时
    var timeInterval = setInterval(function () {

    //如果时、分、秒都为0时将停止当前的倒计时
    if (h == 0 && m == 0 && s == 0) { clearInterval(timeInterval); return; }

    //当秒走到0时,再次为60秒
    if (s == 0) { s = 60; }

    if (s == 60) {

    //每次当秒走到60秒时,分钟减一
    m -= 1;

    //当分等于0时并且小时还多余1个小时的时候进里面看看
    if (m == 0 && h > 0) {

    //小时减一
    h -= 1;

    //分钟自动默认为60分
    m = 60;

    //秒自动默认为60秒
    s = 60;
    }
    }

    //秒继续跳动,减一
    s -= 1;

    //小时赋值
    document.getElementById('f_hh').innerHTML = h;

    //分钟赋值
    document.getElementById('f_mm').innerHTML = m;

    //秒赋值
    document.getElementById('f_ss').innerHTML = s;

    },
    1000);
    </script>
    </body>
    </html>

  • 相关阅读:
    Opencv保存摄像头视频&&各种编码器下视频文件占用空间对比
    生活的 tricks
    生活的 tricks
    词汇的积累 —— 反义词、同义词
    词汇的积累 —— 反义词、同义词
    目标跟踪系列十一:Exploiting the Circulant Structure of Tracking-by-detection with Kernels代码思路
    Java中Integer类的方法
    php中 重载(二)
    协方差的意义
    malloc函数具体解释
  • 原文地址:https://www.cnblogs.com/keke/p/2041286.html
Copyright © 2011-2022 走看看