活动倒计时代码,网站计时器

活动倒计时

购票时间将在 结束

添加自定义HTML

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>活动倒计时</title>
    <style>
        #countdown {
            font-size: 24px;
            font-weight: bold;
            color: red; /* 将字体颜色设置为红色 */
        }
    </style>
    <script>
        function startCountdown(endTime) {
            function updateCountdown() {
                var now = new Date().getTime();
                var distance = endTime - now;

                var days = Math.floor(distance / (1000 * 60 * 60 * 24));
                var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
                var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
                var seconds = Math.floor((distance % (1000 * 60)) / 1000);

                document.getElementById('countdown').innerHTML = 
                    days + "天 " + hours + "小时 " + minutes + "分钟 " + seconds + "秒 ";

                if (distance < 0) {
                    clearInterval(interval);
                    document.getElementById('countdown').innerHTML = "活动已结束";
                }
            }

            updateCountdown();
            var interval = setInterval(updateCountdown, 1000);
        }

        window.onload = function() {
            var endTime = new Date("2099-06-25T23:59:59").getTime();
            startCountdown(endTime);
        };
    </script>
</head>
<body>
    <p>购票时间将在 <span id="countdown"></span> 结束</p>
</body>
</html>

感谢您的观看,对您有用就分享出去吧 !

© 版权声明
THE END
喜欢就支持一下吧
点赞11 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容