2016-02-06 41 views
-1
<button type="submit" class="submitbtn" id="submit" disabled="disabled" name="submit" >Submit Form</button> 
<p id="timeLeft"> You can send form again after: 86400 seconds </p> 
    </div> 

    </form> 
    </div> 

<script type="text/javascript"> 
     setTimeout (function(){ 
     document.getElementById('submit').disabled = null; 
     },86400000); 

     var countdownNum = 86400; 
     incTimer(); 

     function incTimer(){ 
     setTimeout (function(){ 
      if(countdownNum != 0){ 
      countdownNum--; 
      document.getElementById('timeLeft').innerHTML = 'You can send form again after: ' + countdownNum + ' seconds&nbsp;&nbsp;' + '(24hours)'; 
      incTimer(); 
      } else { 
      document.getElementById('timeLeft').innerHTML = 'You can now make a result again!'; 
      } 
     },1000); 
     } 
    </script> 

這是我javacode,但如果我refersh頁面,倒計時也refresh..this提交表單禁用,它會之後24小時(86,400秒)再次提交Java腳本的形式提交倒計時沒有復位,如果刷新

回答

1

,如果你想保存變量

// Put the object into storage when ever you change 
localStorage.setItem('countdownNum', countdownNum); 

// Retrieve the object from storage when at the starting 
var retrievedObject = localStorage.getItem('countdownNum'); 
if(!retrievedObject){ 
    retrievedObject= 86400; 
} 

編輯您可以使用localStorage的: 您可以更改您的代碼此 https://jsfiddle.net/ammar08429/v0pafq0s/2/

並使用setInterval代替每秒呼叫超時 您可以在上面的鏈接中看到示例

+1

什麼部分應該放存儲代碼? – Zipp

+0

好的謝謝你!但是,如果我改變了,我會設置3分鐘,或1小時?爲什麼沒有發生,如果我改變countdownNum? – Zipp

+0

仍然可以點擊即使計時器尚未完成? – Zipp