Preventing multiple clicks on button

后端 未结 14 1902
小鲜肉
小鲜肉 2020-12-02 09:43

I have following jQuery code to prevent double clicking a button. It works fine. I am using Page_ClientValidate() to ensure that the double click is prevented o

相关标签:
14条回答
  • 2020-12-02 10:49

    May be this will help and give the desired functionality :

    $('#disable').on('click', function(){
        $('#disable').attr("disabled", true);
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <button id="disable">Disable Me!</button>
    <p>Hello</p>

    0 讨论(0)
  • 2020-12-02 10:50

    One way you do this is set a counter and if number exceeds the certain number return false. easy as this.

    var mybutton_counter=0;
    $("#mybutton").on('click', function(e){
        if (mybutton_counter>0){return false;} //you can set the number to any
        //your call
         mybutton_counter++; //incremental
    });
    

    make sure, if statement is on top of your call.

    0 讨论(0)
提交回复
热议问题