簡體   English   中英

頁面加載后如何禁用提交按鈕10秒鍾

[英]how to disable a submit button for 10 seconds after the page is loaded

我的問題可能很簡單,但是我只需要一個星期的編程時間,就無法真正理解相對的答案。 所以...需要您的絕地幫助。 頁面加載后如何禁用提交按鈕10秒鍾? 謝謝!

您可以像這樣使用javascript

<input type="submit" id="submitButton" disabled="disabled" />

運用

<script type="text/javascript">
    window.onload=function() {
      setTimeout(function(){
        document.getElementById('submitButton').disabled = null;
      },10000);
    }
</script>

如果需要,下面還會顯示一個ID為“ timeLeft”的容器中的倒計時

 <script type="text/javascript">
    var countdownNum = 10;
    window.onload=function() {
      incTimer();
    }

    function incTimer(){
      setTimeout (function(){
        if(countdownNum != 0){
          countdownNum--;
          document.getElementById('timeLeft').innerHTML = 'Time left: ' + countdownNum + ' seconds';
          incTimer();
        } else {
          document.getElementById('submitButton').disabled = null;
          document.getElementById('timeLeft').innerHTML = 'Ready!';
        }
      },1000);
    }
</script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM