0

这是倒计时的代码。倒计时后,我需要向用户显示一个超链接 <a id="hi" href="page.html">click</a>。假设今天有 Eventtime,或者你可以在那里更改它。我怎样才能做到这一点?

请更正此代码:

  <!DOCTYPE html>
  <html>
   <head>
  </head>
  <body>
            <p id="days" style="display:inline;">00</p> Days 
            <p id="hours" style="display: inline;">00</p> Hrs 
            <p id="minutes" style="display: inline;">00 </p> Min 
            <p id="seconds" style="display: inline;">00</p> seconds Left


            <div id="hi"></div>


    <script type="text/javascript">


            var timer;


        function myLoop() {

            var now = new Date();
            var eventDate = new Date(2017, 9, 21,7,56);

            var currentTime = now.getTime();
            var eventTime = eventDate.getTime();

            var remTime = eventTime - currentTime;

            var s = Math.floor(remTime / 1000);
            var m = Math.floor(s/60);
            var h = Math.floor(m/60);
            var d = Math.floor(h/24);

            h %= 24;
            m %= 60;
            s %= 60;

            h = (h < 10) ? "0" + h : h;
            m = (m < 10) ? "0" + m : m;
            s = (s < 10) ? "0" + s : s;
                if(d>=0 && h>=0 && m>=0 && s>=0)
        {                   

            document.getElementById("days").textContent = d;
            document.getElementById("hours").textContent = h;
            document.getElementById("minutes").textContent = m;
            document.getElementById("seconds").textContent = s;


        if(d>=0 && h>=0 && m>=0 && s>=0)
            {
                timer= setTimeout(myLoop, 1000);

            }

            else
            {
                        clearTimeout(timer);
            document.getElementById('hi').innerHTML=
                               "<a id='hi'href='page.html'>click</a>";

            }

        }


    }

    myLoop();
    </script>
 </body>
 </html>

那么如何在清除超时后设置超链接。我在 clearTimeout 语句之前尝试过仍然无法正常工作。实际上,我必须在一个部门内显示这个锚标记,在计数器超时后将该部门重定向到给定的超链接。

4

0 回答 0