首页 > 技术文章 > 20-------------------setTimeout模拟setinterval的使用

clcloveHuahua 2016-01-26 13:02 原文

 1 <head>
 2 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
 3     <title></title>
 4 
 5    
 6     <script type="text/javascript">
 7         
 8         onload = function () {
 9             setTimeout(changeTime, 1000);//1秒改变一次时间
10         };
11 
12         function changeTime() {
13             var time = document.getElementById("time").innerHTML;
14             time--;
15             if (time > 0) {
16                 document.getElementById("time").innerHTML = time;
17 
18                 setTimeout(changeTime, 1000);
19 
20             } else {
21                 window.location.href = "UserInfoList.ashx";
22             }
23         };
24 
25     </script>
26 
27 
28 </head>
29 <body>
30     服务器很忙,<span id="time">5</span>秒后跳转到<a href="UserInfoList.ashx">主页面</a>。。
31 </body>
32 </html>

 

推荐阅读