JS加html做一个倒计时

2025-02-23 11:43:08
推荐回答(1个)
回答1:





JS

    function countdown ()
    {
        var end = new Date (2014, 10, 29, 3);
        var now = new Date ();
         
        var m = Math.round ((end - now) / 1000);
        var day = parseInt (m / 24 / 3600);
        var hours = parseInt ((m % (3600 * 24)) / 3600);
        var minutes = parseInt ((m % 3600) / 60);
        var seconds = m % 60;
         
        if (m < 0)
        {
            document.getElementById ("clock").innerHTML = '0';
            return;
        }
        document.getElementById ("clock").innerHTML = "离开始还剩" + day + "天" + hours + "小时" + minutes + "分钟" + seconds
                + "秒";
        setTimeout ('countdown()', 1000);
    }
    window.onload = function ()
    {
        countdown ();
    }