Disable button on form submission

前端 未结 17 1675
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 00:13

I have a button that I would like to disable when the form submits to prevent the user submitting multiple times.

I have tried naively disabling the button with java

17条回答
  •  既然无缘
    2020-12-01 01:15

    So simply disabling the button via javascript is not a cross-browser compatible option. Chrome will not submit the form if you just use OnClientClick="this.disabled=true;"
    Below is a solution that I have tested in Firefox 9, Internet Explorer 9, and Chrome 16:

    
    

    Then register 'disableButton' with the click event of your form submission button, one way being:

    
    

    Worth noting that this gets around your issue of the button being disabled if client side validation fails. Also requires no server side processing.

提交回复
热议问题