6、倒計時10秒
阿新 • • 發佈:2018-02-22
pre cal bsp minimum java edge function dev 。。
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div id="showtimes">加載中。。。</div> <script type="text/javascript"> //設定倒數秒數 var t = 10; //顯示倒數秒數 function showTime(){ t -= 1; document.getElementById(‘showtimes‘).innerHTML= t; if(t==0){ location.href=‘http://www.baidu.com‘; } //每秒執行一次,showTime()setTimeout("showTime()",1000); } //執行showTime() showTime(); </script> </body> </html>
效果圖:
當倒計時到等於0的時候停止為0:
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <div id="showtimes">加載中。。。</div> <script type="text/javascript"> //設定倒數秒數 var t = 10; //顯示倒數秒數 function showTime(){ t -= 1; document.getElementById(‘showtimes‘).innerHTML= t; //每秒執行一次,showTime() s=setTimeout("showTime()",1000); //若倒計時到等於0,就停止 if(t==0){ t = 0; clearTimeout(s); } } //執行showTime() showTime(); </script> </body> </html>
6、倒計時10秒