Home  >  Article  >  Web Front-end  >  各种页面定时跳转(倒计时跳转)代码总结_javascript技巧

各种页面定时跳转(倒计时跳转)代码总结_javascript技巧

WBOY
WBOYOriginal
2016-05-16 17:18:50792browse

下面对实现页面定时跳转(也称倒计时跳转)做一下总结,各种定时跳转代码记录如下:

(1)使用setTimeout函数实现定时跳转(如下代码要写在body区域内)

复制代码 代码如下:



(2)html代码实现,在页面的head区域块内加上如下代码
复制代码 代码如下:




(3)稍微复杂点,多见于登陆之后的定时跳转
复制代码 代码如下:




js定时跳转页面的方法


<script> <BR>var t=10;//设定跳转的时间 <BR>setInterval("refer()",1000); //启动1秒定时 <BR>function refer(){ <BR>if(t==0){ <BR>location="http://www.baidu.com"; //#设定跳转的链接地址 <BR>} <BR>document.getElementById('show').innerHTML=""+t+"秒后跳转到百度"; // 显示倒计时 <BR>t--; // 计数器递减 <BR>//本文转自: <BR>} <BR></script>


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn