Javascript 實現倒計時(10秒)自動關閉網頁

JS倒計時10秒 實現功能javascript

實例代碼一:css

                  <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

 

實例代碼二:java

                  <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>函數

相關文章
相關標籤/搜索