有时候需要做一个跳转的页面,而我们希望在页面上能够显示跳转时间的倒计时。
下面这个javascript就能很好地解决这个问题。
<div> <h2><a href="https://blog.gimhoy.com/archives/tag/html" title="View all posts in HTML" target="_blank">HTML</a>倒计时页面跳转<a href="https://blog.gimhoy.com/archives/tag/js" title="View all posts in JS" target="_blank">JS</a>代码</h2> </div> <div id="content"> <div id="Layer1"> <script type="text/javascript"> function countDown(secs,surl){ //alert(surl); jumpTo.innerText=secs; if(--secs>0){ setTimeout("countDown("+secs+",'"+surl+"')",1000); } else{ location.href=surl; } } </script> <!--脚本结束--> <span id="jumpTo">10</span>秒后自动跳转 <script type="text/javascript">countDown(10,'index1.asp');</script><a href="index1.asp">点击直接进入</a> </div> </div>
js下载:countdown.js