js控制n秒后跳转到指定页面,并显示倒计时

发布时间:2018-07-11 22:25:58编辑:丝画阁阅读(288)

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <head runat="server">
  4. <title>setTimeout</title>
  5. </head>
  6. <body>
  7. <form id="form1" runat="server">
  8. <div id='div1'>
  9. </div>
  10. </form>
  11. </body>
  12. </html>


  13. <script type="text/javascript">
  14. //设定倒数秒数
  15. var t = 10;
  16. //显示倒数秒数
  17. function showTime(){
  18. t -= 1;
  19. document.getElementById('div1').innerHTML= t;
  20. if(t==0){
  21. location.href='http://www.baidu.com';
  22. }
  23. //每秒执行一次,showTime()
  24. setTimeout("showTime()",1000);
  25. }


  26. //执行showTime()
  27. showTime();
  28. </script>


  • 关键字