`
jasonw68
  • 浏览: 149428 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

js定时执行

阅读更多
<html>
<head>
<title>自动跳转</title>
</head><body>
<span id="spanSeconds"></span>
</body>
</html>
<script language="JavaScript">
<!--
var seconds = 3;
var defaultUrl = "http://www.google.cn"; 
onload = function() {        
window.setInterval(redirection, 1000);    
}

function redirection(){    
if (seconds <= 0)    {        
window.clearInterval();        
return;   
 }    
 seconds --;   
 document.getElementById('spanSeconds').innerHTML = seconds;     
if (seconds == 0)   
 {        
window.clearInterval();      
  location.href = defaultUrl;  
  }
}
//-->
</script>

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics