显示时间倒计时

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript">

        var maxtime = 3 * 60 * 60 //一个小时,按秒计算,自己调整!

        function CountDown() {

            if (maxtime >= 0) {

                hours = Math.floor(maxtime / 3600)

                minutes = Math.floor((maxtime - 3600 * hours) / 60);

                seconds = Math.floor(maxtime % 60);

                msg = "距离结束还有:" + hours + "时" + minutes + "分" + seconds + "秒";

                document.getElementById("timer").innerHTML = msg;

                if (maxtime == 5 * 60) alert('注意,还有分钟!');

                --maxtime;

            } else {

                clearInterval(timer);

                alert("时间到,结束!");

            }

        }

        timer = setInterval("CountDown()", 1000);

    </script>
</head>
<body>
    <div id="timer">
    </div>
</body>
</html>

运行截图:

posted on 2013-01-23 13:56  程序小民工  阅读(143)  评论(0)    收藏  举报

导航