php - how to disable a submit button for 10 seconds after the page is loaded - Stack Overflow

My question is probably simple, but I'm only a week into programming, and I cant really understand

My question is probably simple, but I'm only a week into programming, and I cant really understand the relative answers that I could find. So... need your Jedi help. How to disable a submit button for 10 seconds after the page is loaded? Thanks!

My question is probably simple, but I'm only a week into programming, and I cant really understand the relative answers that I could find. So... need your Jedi help. How to disable a submit button for 10 seconds after the page is loaded? Thanks!

Share Improve this question edited Apr 24, 2013 at 8:49 mplungjan 179k28 gold badges182 silver badges240 bronze badges asked Apr 24, 2013 at 8:42 user2309163user2309163 531 gold badge2 silver badges5 bronze badges 3
  • 2 have the button with the disabled tag, use a javascript setTimeout() timer for 10 seconds which after that period will change the button property to be not disabled. – Dave Commented Apr 24, 2013 at 8:44
  • We can do it by using jquery ... use .hide() – Nipun Tyagi Commented Apr 24, 2013 at 8:44
  • We can also do it without using jQuery at all – mplungjan Commented Apr 24, 2013 at 8:46
Add a ment  | 

1 Answer 1

Reset to default 6

You can use javascript like this

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

using

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

The following will additionally show a countdown in a container with ID="timeLeft" if you need one

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745410774a4626523.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信