您的位置:首页 > Web前端 > JavaScript

js实现倒计时

2016-07-01 10:34 204 查看
 $(function () {
            var sec_str = "<%=promotion_second %>";
            if (parseInt(sec_str) < 0) {
                timer(sec_str.substring(1));
            }
            else {
                timer(sec_str);
            }
        });
        //倒计时
        function timer(intDiff) {
            $('#hour_show').html("");
            $('#minute_show').html("");
            $('#second_show').html("");
            time_str = window.setInterval(function () {
                var day = 0,
        hour = 0,
        minute = 0,
        second = 0;
                if (intDiff > 0) {
                    hour = Math.floor(intDiff / 3600);
                    minute = Math.floor((intDiff % 3600) / 60);
                    second = Math.floor(intDiff % 60);
                }
                if (hour <= 9) hour = '0' + hour;
                if (minute <= 9) minute = '0' + minute;
                if (second <= 9) second = '0' + second;
                $('#hour_show').html(hour);
                $('#minute_show').html(minute);
                $('#second_show').html(second);
                intDiff--;
            }, 1000);
        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: