js实现活动时间倒计时

//倒计时
    var not3djs = ['活动还剩', '天', '小时', '分', '秒', '活动时间已结束']
    var timer;
    //活动时间单位-秒
    var not3exptime = 60;

    function formatSeconds(n) {
        console.log(n);
        var t = parseInt(n)
        , e = 0
        , s = 0
        , a = 0
        , o = "";
        return n < 60 ? o = t + not3djs[4] : (t >= 60 && (e = parseInt(t / 60),
        t = parseInt(t % 60),
        e >= 60 && (s = parseInt(e / 60),
        e = parseInt(e % 60),
        s >= 24 && (a = parseInt(s / 24),
        s = parseInt(s % 24)))),
        t > -1 && (t = parseInt(t) >= 10 ? t : "0" + t,
        o = "" + t + " " + not3djs[4]),
        e > 0 && (e = parseInt(e) >= 10 ? e : "0" + e,
        o = "" + e + " " + not3djs[3] + o),
        s > 0 && (o = "" + parseInt(s) + " " + not3djs[2] + o),
        a > 0 && (o = "" + parseInt(a) + " " + not3djs[1] + o)),
        not3djs[0] + o
    }
    function CountDown() {
        --not3exptime;
        if(not3exptime >= 0 ){
            msg = formatSeconds(not3exptime);
        }else{
            clearInterval(timer);
            msg = not3djs[5];
        }
        $("#remainTime_1").html(msg)
    }
    timer = setInterval(function(){
        CountDown();
    },1000)

你可能感兴趣的:(JavaScript,html,html5,javascript)