這篇文章主要介紹了javascript頁面倒計時實現方法,可實現簡單的頁面倒計時及自動提交表單功能,非常簡單實用,需要的朋友可以參考下
本文實例講述了javascript頁面倒計時實現方法。分享給大家供大家參考。具體實現方法如下:
- <html>
- <head>
- </head>
- <body>
- <input type="text" name="mss" id="mss"/>
- <form action="./index.html">
- <input type="text" value="name" name="name"/>
- </form>
- <body>
- </html>
- <script type="text/javascript">
- <!--
- window.onload=function(){
- daojishi();
- }
- var counttime=120*60;//總秒鐘
- function daojishi(){
- if(counttime>=0){
- var ms = counttime%60;//余數 89%60==29秒
- var mis = Math.floor(counttime/60);//分鐘
- if(mis>=60){
- var hour=Math.floor(mis/60);
- mis=Math.floor((counttime-hour*60*60)/60);
- document.getElementById("mss").value=hour+"小時"+mis+"分"+ms+"秒數";
- }else if(mis>=1){
- document.getElementById("mss").value=mis+"分"+ms+"秒數";
- }else{
- document.getElementById("mss").value=ms+"秒數";
- }
- counttime--;
- vartt = window.setTimeout("daojishi()",1000);
- }else{
- window.clearTimeout(vartt);
- window.confirm("考試時間結束,請單擊提交");
- tijiao();
- }
- }
- function tijiao(){
- document.forms[0].submit();
- }
- //-->
- </script>
希望本文所述對大家的javascript程序設計有所幫助。
新聞熱點
疑難解答
圖片精選