On many forums I saw a timer embedded in the button, and until the time (displayed on the timer) passes, the button is in the disabled state. I would be grateful for an example or a working script. (gogl did not help)
- 2what exactly you fail? - Dmitriy Kondratiuk
- google driven development? - AK ♦
|
1 answer
$(function() { $('button').click(function() { var but = $(this); var time = 30; //задаем время в течении которого кнопка будет не активна var timeInterval = setInterval(function() { if (time <= 0) { clearInterval(timeInterval); } if (time == 0) { $(but).children('span').html(""); $(but).prop("disabled", false); } else { $(but).children('span').html(time); $(but).prop("disabled", true); } time = time - 1; }, 1000); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button>knopka <span></span> </button> <button>knopka <span></span> </button> <button>knopka <span></span> </button> - oneAnd yet, although you see that the top-starter does not want to hit the finger ("do everything for me"), you still decided to answer. Moreover, the answer is pure code, without any explanation why. Better not chase the turnip next time. - AK ♦
- one@AK opinion of other users may not coincide with yours. If the author of the question "hit the finger", the question would not have arisen at all. You can cast your vote against a question or answer if you don’t like them. Or vote to close the question if you think that it is of inadequate quality or violates the rules of SO. - Dmitry
- @ AK agrees with you that the author of the question and the thumb did not hit to solve the problem. I just wondered if I could solve this problem and since the code has already been written then why not publish it. In terms of explanations, if the author still wants to figure it out, you can read the documentation or ask here in the comments. - Dmitriy Kondratiuk
|