页面倒计时自动返回示例

 1 <%@ page language="java" isErrorPage="true" %>
 2 <%@ page language="java" contentType="text/html;charset=utf-8"  pageEncoding="UTF-8"%>
 3 <!DOCTYPE html>
 4 <html>
 5 <head>
 6     <title>error</title>
 7         <style type="text/css">
 8         .error{color: #666;}
 9         .error #time{color: red;}
10     </style>
11 </head>
12 <body>
13     <div class="error text-center">
14         <h3>服务器忙,请稍后重试!</h3>
15         <p>页面将在<span id="time">10</span>秒后跳转<a href="/index">首页</a>,请稍等...</p>
16     </div>
17 </h2>
18 <script>
19     var sum =10;
20     function load(){
21         for(var i = sum-1;i>=0;i--){
22             changeTime(i);
23         }
24     }
25     function changeTime(i){
26         setTimeout(function(){
27             document.getElementById("time").innerHTML=i;
28             if(i < 1){
29                 location.href="/index";
30                 //history.back(); 返回上个页面
31             }
32         },(sum-i)*1000);
33     }
34     load();
35 </script>
36 </body>
37 </html>

 

posted @ 2014-02-20 10:33  麦克优雅  阅读(636)  评论(0编辑  收藏  举报