Javascript Disable button and reenable it after 5 seconds

前端 未结 2 1832
日久生厌
日久生厌 2021-01-06 18:52

I want to disable my button on click and then reenable in after 5 seconds but its not working properly.

  function submitPoll(id){
      document.getElementB         


        
2条回答
  •  清酒与你
    2021-01-06 19:16

    Like Zee said .delay is a JQuery function which can only be used on a JQuery object. Currently you are only using a reference to an HTML element which is produced by .getElementById()

    If you are wanting a button that disables itself. I went ahead and made a little example on jsfiddle.

    http://jsfiddle.net/1z0bx0t7/

    Using code that looks like:

    function submitPoll() {
        document.getElementById("votebutton").disabled = true;
        setTimeout(function() {
            document.getElementById("votebutton").disabled = false;
        }, 5000);
    }
    document.getElementById("votebutton").addEventListener("click", submitPoll);
    

提交回复
热议问题