开发者

Enabling a button based on condition with jQuery

I have a "Save Settings" button which is of type 'image'. I want it to be enabled only after a checkbox is checked by the user I m using..

$('#btnSaveProfile').attr("disabled",true);    
$('#btnSaveProfile').click(function(){
            if ($("#rdAccept").is(':checked')) 
            {
                $('#btnSaveProfile').attr("disabled",false);
                updateProfile();// calling a functi开发者_如何学编程on here that saves data.
            }
        });

This does not work, any inputs....please


You are disabling the element with id btnSaveProfile and then attaching a click handler, which will never get run because its disabled. You need to add a click handler to your checkbox, which will re-enable the save button.


You are not using the checkbox click event, try the following

var $btn = $('#btnSaveProfile').attr("disabled",true);   

$('#rdAccept').click(function(){
   if (this.checked) {
       $btn.removeAttr("disabled");
   }
});

$btn.click(updateProfile);


$('#btnSaveProfile').attr("disabled",''); enables the button

$('#btnSaveProfile').attr("disabled",'disabled'); disables the button

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜