admin管理员组

文章数量:1312861

I have a form with a submit button. I want to disable the submit button for 10 seconds, and show a countdown, at the end of which the button bees clickable.

How would I do that? Im using jquery on the site, but Im not a JS programmer.

I have a form with a submit button. I want to disable the submit button for 10 seconds, and show a countdown, at the end of which the button bees clickable.

How would I do that? Im using jquery on the site, but Im not a JS programmer.

Share Improve this question asked Aug 28, 2010 at 3:01 user15063user15063 1
  • No everyone has a luxury of delegating different tasks to different programmers. – user15063 Commented Aug 28, 2010 at 17:10
Add a ment  | 

1 Answer 1

Reset to default 8

Let's keep it simple. If you'd like an explanation of what is going on, let me know:

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

        var countdownNum = 10;
        incTimer();

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

    <body>
    <form>
        <input type="submit" disabled="disabled" id="submitButton" />
        <p id="timeLeft">Time Left: 10 seconds</p>
    </form>
    </body>
</html>

本文标签: javascriptHow to disable form button click function for X secondsStack Overflow