Javascript 实现倒计时(10秒)自动关闭网页

JS倒计时10秒 实现功能

实例代码一:

                  <html>
                  <title>倒计时关闭网页</title>
                  <head>
                  <script language="javascript">
                  var cTime=10;//这个变量是倒计时的秒数设置为10就是10秒
                  function TimeClose()
                  {
                       window.setTimeout('TimeClose()',1000);//让程序每秒重复执行当前函数。
                       if(cTime<=0)//判断秒数如果为0
                         CloseWindow_Click();//执行关闭网页的操作
                       this.ShowTime.innerHTML="倒计时"+cTime+"秒后关闭当前窗口";//显示倒计时时间
                       cTime--;//减少秒数
                  }
                  function CloseWindow_Click()
                  {
                       window.close();
                  }
                  </script>
                  </head>
                  <body onLoad="TimeClose();">
                         <div id="ShowTime">倒计时10秒后关闭当前窗口</div>
                         <input type="button" name="CloseWindow" 
                  onClick="CloseWindow_Click();" value="立即关闭当前网页">
                  </body>
                  </html>

 

实例代码二:

                  <html xmlns="http://www.w3.org/1999/xhtml">
                  <head>
                  <meta http-equiv="Content-Type" content="text/html; 
                  charset=gb2312" />
                  <title>用户管理中心</title>
                  <link href="Include/Style.Css" rel="stylesheet" 
                  type="text/css" />
                  <title>请稍等...</title>
                  <script language="javascript">
                  <!--
                  var WaitTime = 10; //等待的时间,单位秒
                  function WaitDo(){
                         if(WaitTime > 0){
                             putOutMsg.innerHTML = "本页面将在"+ WaitTime +"秒钟后自动关闭";
                             WaitTime --;
                             setTimeout("WaitDo()",1000);
                         }
                         else
                         {
                             window.close();
                         }
                  }
                  //-->
                  </script>
                  <style type="text/css">
                  span,font{font-size:16px; font-weight:bold;}
                  </style>
                  </head>
                  <body onLoad="WaitDo();" style="margin:20px;">
                  <span id="putOutMsg" class="OpenFont"></span>
                  </body>
                  </html>

 


转载于:https://my.oschina.net/rabondai/blog/227269

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值