倒计时指定时间之后实现页面跳转效果

倒计时指定时间之后实现页面跳转效果:
通过倒计时指定秒数之后实现网页的跳转效果,在很多效果中都有应用,例如,登陆或者注册成功之后倒计时指定时间跳转到某个页面,下面就通过代码实例介绍一下如何实现此效果。
代码实例如下:

<!DOCTYPE html> 
<html> 
<head> 
<meta charset=" utf-8"> 
<meta name="author" content="http://www.softwhy.com/" /> 
<title>蚂蚁部落</title> 
<style type="text/css"> 
#thediv
{
  width:150px;
  height:30px;
  text-align:center;
  margin:0px auto;
  font-size:12px;
}
</style> 
<script type="text/javascript">  
window.onload=function(){
  var odiv=document.getElementById("thediv");
  var timer=null;
  function Countdown(count,obj){
    return function(){
      if(count>0)
      {
        count=count-1;
        obj.innerHTML="剩余"+count+"跳转到指定网页";
      }
      else
      {
        location.href="http://www.softwhy.com";
        clearInterval(timer);
      }
    }
  }
  timer=setInterval(Countdown(20,odiv),1000);
}
</script> 
</head> 
<body> 
<div id="thediv"></div>
</body> 
</html>

 以上代码实现了我们的要求,可以在倒计时20秒之后实现跳转效果,代码很简单这里就不介绍了,可以参阅相关阅读。

相关阅读:
1.innerHTML属性可以参阅js的innerHTML属性的用法一章节。 
2.setInterval()函数可以参阅setInterval()函数用法详解一章节。 
3.clearInterval()函数可以参阅window对象的clearInterval()方法一章节。 

原文地址是:http://www.softwhy.com/forum.php?mod=viewthread&tid=11860

更多内容可以参阅:http://www.softwhy.com/javascript/

猜你喜欢

转载自softwhy.iteye.com/blog/2275739