抢购倒计时

<body>

    <div id="condown">

    </div>

</body>

<script type="text/javascript">

    function _fresh() {

        var endtime = new Date(2015,3,15,23,59,59);

        var nowtime = new Date();

        var leftsecond = parseInt((endtime.getTime() - nowtime.getTime()) / 1000);

        __d = parseInt(leftsecond / 3600 / 24);

        __h = parseInt((leftsecond / 3600) % 24);

        __m = parseInt((leftsecond / 60) % 60);

        __s = parseInt(leftsecond % 60);

        document.getElementById('condown').innerHTML = __d + "天 " + __h + "小时" + __m + "分" + __s + "秒";

        if (leftsecond <= 0) {

            document.getElementById('condown').innerHTML = "抢购已结束";

            clearInterval(sh);

        }

    }

    _fresh();

    var sh;

    sh = setInterval(_fresh, 1000);

</script>

 

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