Removal of disabled the timer at the button



  • Many forums have seen the timer built into the button, and as long as the time (displayed in the timer) does not pass, the button is incapable of being disabled. I'll be grateful for an example or a working crypt.



  • $(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>




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2