分秒毫秒倒计时

<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function() {
            var times = 120 * 100; // 120秒
            countTime = setInterval(function() {
                times = --times < 0 ? 0 : times;
                var mi = Math.floor(times / 100 /60%60 ).toString();
                if (mi.length <= 1) {
                    mi = "0" + mi;
                }
                var ms = Math.floor(times / 100 % 60).toString();

                if(ms.length <= 1) {
                    ms = "0" + ms;
                }
                var hm = Math.floor(times % 100).toString();
                if(hm.length <= 1) {
                    hm = "0" + hm;
                }
                if(times == 0) {
                    alert("游戏结束");
                    clearInterval(countTime);
                }
                // 获取分钟、毫秒数
                $(".a").html(mi);
                $(".b").html(ms);
                $(".c").html(hm);
            }, 10);
        });
    </script>
</head>
<body>
<div class="a"></div>
<div class="b"></div>
<div class="c"></div>
</body>
</html>

 

posted @ 2017-06-05 16:47  曦言鸢默  阅读(746)  评论(0编辑  收藏  举报