1 <!DOCTYPE html> 2 <html> 3 <meta charset="utf-8" /> 4 <title>倒计时跳转界面</title> 5 <head> 6 </head> 7 <body> 8 <p> 9 <span id="timer"></span> 秒后自动返回 10 <a href="http://www.cnblogs.com/beiz/">直接跳转</a> 11 </p> 12 13 <script language="javascript" type="text/javascript"> 14 window.onload = function(){ 15 var time = 3; //设置时间为几秒 16 var timer = document.getElementById(‘timer‘); //获取ID为timer的对象 17 timer.innerHTML = time; //初始化显示秒数 18 time = time - 1; 19 var g = window.setInterval(function(){ 20 if(time<0){ 21 window.clearTimeout(g); //清除动画 22 window.location.href = ‘http://www.cnblogs.com/beiz/‘; //跳转到指定地址 23 //window.history.back(-1); //后退 24 } else { 25 showTime(); 26 } 27 },1000); 28 //显示函数 29 function showTime(){ 30 timer.innerHTML = time; 31 time--; 32 } 33 }; 34 </script> 35 </body> 36 </html>
时间: 2024-09-30 11:45:25