Disabling the button after once click

后端 未结 9 1504
遥遥无期
遥遥无期 2020-11-28 09:32

I need to disable a button once it\'s clicked so the user can\'t click it more than once. (My application is written in MVC ASP.NET, I\'ve done this in a normal ASP.NET appl

相关标签:
9条回答
  • 2020-11-28 10:22
    $("selectorbyclassorbyIDorbyName").click(function () {
      $("selectorbyclassorbyIDorbyName").attr("disabled", true).delay(2000).attr("disabled", false);
    });
    

    select the button and by its id or text or class ... it just disables after 1st click and enables after 20 Milli sec

    Works very well for post backs n place it in Master page, applies to all buttons without calling implicitly like onclientClick

    0 讨论(0)
  • 2020-11-28 10:26

    think simple

    <button id="button1" onclick="Click();">ok</button>
    <script>
        var buttonClick = false;
        function Click() {
            if (buttonClick) {
                return;
            }
            else {
                buttonClick = true;
                //todo
                alert("ok");
                //buttonClick = false;
            }
        }
    </script>
    

    if you want run once :)

    0 讨论(0)
  • 2020-11-28 10:31

    To disable a submit button, you just need to add a disabled attribute to the submit button.

    $("#btnSubmit").attr("disabled", true);
    

    To enable a disabled button, set the disabled attribute to false, or remove the disabled attribute.

    $('#btnSubmit').attr("disabled", false);
    

    or

    $('#btnSubmit').removeAttr("disabled");
    
    0 讨论(0)
提交回复
热议问题