Js倒计时函数

//倒计时
function timer(intDiff) {
    var nextime = intDiff;
    var intervalId = window.setInterval(function () {
        nextime--;
        var day = 0,
        hour = 0,
        minute = 0,
        second = 0; //时间默认值
        if (nextime > 0) {
            day = Math.floor(nextime / (60 * 60 * 24)); //天
            hour = Math.floor(nextime / (60 * 60)) - (day * 24); //小时
            minute = Math.floor(nextime / 60) - (day * 24 * 60) - (hour * 60); //分钟
            second = Math.floor(nextime) - (day * 24 * 60 * 60) - (hour * 60 * 60) - (minute * 60); //秒
        }
        if (hour <= 9)
            hour = '0' + hour;
        if (minute <= 9)
            minute = '0' + minute;
        if (second <= 9)
            second = '0' + second;

        $("#timeShow").html(minute + ":" + second);

        if (nextime == 0) {
            clearInterval(intervalId);
        }
    }, 1000);
}

你可能感兴趣的:(Js倒计时函数)