开发者

How to disable button on form submit exactly like stackoverflow ask question?

开发者 https://www.devze.com 2022-12-26 20:41 出处:网络
I have seen stackoverflow ask question page they disable button until my postback event i开发者_JAVA技巧s finished when i post the question and redirect me to my question page... How to do this in asp

I have seen stackoverflow ask question page they disable button until my postback event i开发者_JAVA技巧s finished when i post the question and redirect me to my question page... How to do this in asp.net/jquery?


$('#myform').submit(function(){
    $('input[type=submit]', this).attr('disabled', 'disabled');
});

to re-enable your button after a client side action has completes, such as AJAX:

$('#myform:input[type=submit]').removeAttr('disabled');


The basic concept is that you would have jquery add a client-side click event which disabled the button (i.e. $('#controlName').attr("disabled", "disabled"); ). What thing to remember is that you want to return TRUE from that method, so that the standard form post functionality will still work.

Something like:

$(function(){
   $('#controlName').click(function(){
      $('#controlName').attr("disabled", "disabled");
      return true;
   });
});
0

精彩评论

暂无评论...
验证码 换一张
取 消