专业编程基础技术教程

网站首页 > 基础教程 正文

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

ccvgpt 2024-07-19 12:56:28 基础教程 10 ℃
  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>

Tags:

最近发表
标签列表