开发者

Unable to disable form submit with an input button that is an image

开发者 https://www.devze.com 2023-04-08 03:25 出处:网络
How do I disable the form from submitting? I have tried the following chunk of jQuery with no success - any ideas?

How do I disable the form from submitting? I have tried the following chunk of jQuery with no success - any ideas?

http://pastebin.com/W7hjaSe0

$('#signup').submit(function(){
    $('input[type=button]', this).attr('dis开发者_高级运维abled', 'disabled');
});


I am not sure if you are looking for the button to be physically greyed out, or just prevent default action. Here is an example that will run your code on click, grey out the button, and then prevent the default form submission behavior.

$('#signup').submit(function(){
     $('input[type=button]', this).attr('disabled', 'disabled').css('opacity',0.5); 
     return false;
}); 


I think the problem is your selector, this is not a "button" type

Change

$('input[type=button]', this).attr('disabled', 'disabled');

To

$('input#signup', this).attr('disabled', 'disabled');


A simple return false should do the trick. If that doesn't work you can always use the preventDefault() function of event.

0

精彩评论

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