zoukankan      html  css  js  c++  java
  • 倒计时

    <body onload="show_time();">

    <p class="tit2">限时秒杀倒计时剩余时间:</p>
    <ul class="time clearfix">
    <li>
    <div>
    <p id="day">00</p><span>天</span></div>
    </li>
    <li>
    <div>
    <p id="hour">00</p><span>小时</span></div>
    </li>
    <li>
    <div>
    <p id="min">00</p><span>分钟</span></div>
    </li>
    <li>
    <div>
    <p id="sec">00</p><span>秒</span></div>
    </li>
    </ul>

    js

    function show_time(){
    var time_start = new Date().getTime(); //设定当前时间
    var time_end = new Date("2015/09/27 00:00:00").getTime(); //设定目标时间
    // 计算时间差
    var time_distance = time_end - time_start;
    // 天
    var int_day = Math.floor(time_distance/86400000)
    time_distance -= int_day * 86400000;
    // 时
    var int_hour = Math.floor(time_distance/3600000)
    time_distance -= int_hour * 3600000;
    // 分
    var int_minute = Math.floor(time_distance/60000)
    time_distance -= int_minute * 60000;
    // 秒
    var int_second = Math.floor(time_distance/1000)
    // 时分秒为单数时、前面加零
    if(int_day < 10){
    int_day = "0" + int_day;
    }
    if(int_hour < 10){
    int_hour = "0" + int_hour;
    }
    if(int_minute < 10){
    int_minute = "0" + int_minute;
    }
    if(int_second < 10){
    int_second = "0" + int_second;
    }
    // 显示时间
    $("#day").html(int_day);
    $("#hour").html(int_hour);
    $("#min").html(int_minute);
    $("#sec").html(int_second);
    // 设置定时器
    setTimeout("show_time()",1000);
    }

    </body>

  • 相关阅读:
    博客最新博文通告
    博文快速导航
    创业
    央行回应中国版数字货币:与人民币等价 不会让钱贬值
    高屋建瓴
    高层人对事的处理
    老板的区别
    沟通的四大法则
    赚钱规则
    合伙做生意的原则
  • 原文地址:https://www.cnblogs.com/zhouyx/p/4760690.html
Copyright © 2011-2022 走看看