TOP

JS倒计时——天时分秒(一)
2017-10-10 15:34:07 】 浏览:10045
Tags:倒计时 天时 分秒

HTML代码:
<div id="times_wrap" class="time_num">
    距离结束时间:
    <div class="time_w">
        <b id="times_d" class="time"> </b>天
        <b id="times_h" class="time"> </b>时
        <b id="times_m" class="time"> </b>分
        <b id="times_s" class="time"> </b>秒
    </div>
</div>

java script代码:
<script type="text/java script">
setTimeout("show_time()",1000);
var time_wrap = document.getElementByIdx_x("times_wrap");
var time_d = document.getElementByIdx_x("times_d");
var time_h = document.getElementByIdx_x("times_h");
var time_m = document.getElementByIdx_x("times_m");
var time_s = document.getElementByIdx_x("times_s");

var time_end = new Date("2012/10/29 08:00:00");  // 设定结束时间
time_end = time_end.getTime();

function show_time(){
    var time_now = new Date();  // 获取当前时间
        time_now = time_now.getTime();
    var time_distance = time_end - time_now;  // 结束时间减去当前时间
    var int_day, int_hour, int_minute, int_second;
    if(time_distance >= 0){
        // 天时分秒换算
        int_day = Math.floor(time_distance/86400000)
        time_distance -= int_day * 86400000;
        int_hour = Math.floor(time_distance/3600000)
        time_distance -= int_hour * 3600000;
        int_minute = Math.floor(time_distance/60000)
        time_distance -= int_minute * 60000;
        int_second = Math.floor(time_distance/1000)
 
        // 时分秒为单数时、前面加零站位
        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;
        
        // 显示时间
        time_d.innerHTML = int_day;
        time_h.innerHTML = int_hour;
  &n
JS倒计时——天时分秒(一) https://www.cppentry.com/bencandy.php?fid=107&id=134007

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇CSS实现单行、多行文本溢出显示省.. 下一篇Vue组件实例间的直接访问