开发者

Disable form using jQuery after submission

开发者 https://www.devze.com 2022-12-21 18:11 出处:网络
Is ther开发者_如何学Goe any way to disable entire form using jQuery after submission?To disable all the form elements in the form (this code will actually disable all input elements in all form tags o

Is ther开发者_如何学Goe any way to disable entire form using jQuery after submission?


To disable all the form elements in the form (this code will actually disable all input elements in all form tags on the page, so you will want to make the selector more specific).

$(function() {
    $("#idOfYourSubmitButton").click(function() {
        $("form input").attr("disabled","disabled"); 
    });
})


If you only have 1 form on the page (and don't plan on adding one any time soon):

$( function( )
{
     $( 'form' ).submit( function( )
     {
          $( this ).find( 'input, textarea' ).attr( 'disabled', 'disabled' );
     } );
} );

If you need to use an id (<form id="idOfYourSubmitButton">):

$( function( )
{
     $( '#idOfYourSubmitButton' ).submit( function( )
     {
          $( this ).find( 'input, textarea' ).attr( 'disabled', 'disabled' );
     } );
} );


Sure. Just catch the onsubmit event, submit the form, then do a select on the submit element and set it to disabled. See http://www.w3.org/TR/html401/interact/forms.html#h-17.12.1 for all the exciting details.


$(function() {
    $("#idOfYourSubmitButton").click(function() {
        $(this).attr("disabled","disabled");    
    });
})

but keep in mind that if something goes bad you want to re-enable the button with .removeAttr(“disabled”);

0

精彩评论

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