Javascript 按钮赢了';不要使用jQuery自行重新启用它

Javascript 按钮赢了';不要使用jQuery自行重新启用它,javascript,jquery,Javascript,Jquery,我不明白为什么我的按钮在单击另一个按钮时无法重新启用。任何帮助都将不胜感激 我的代码如下: $(document).ready(function() { $('#btnAdd').click(function() { // enable the "remove" button $('#btnDele').attr('disabled',''); } }); 此处演示: 应该做到这一点。我使用Jquery UI并使用$('btnDele')。按钮

我不明白为什么我的按钮在单击另一个按钮时无法重新启用。任何帮助都将不胜感激

我的代码如下:

$(document).ready(function() {
    $('#btnAdd').click(function() { 
        // enable the "remove" button
        $('#btnDele').attr('disabled','');
    }
});
此处演示:


应该做到这一点。

我使用Jquery UI并使用$('btnDele')。按钮(“启用”),而不是使用.attr函数;

必须完全删除“禁用”属性,而不仅仅是设置为null/空字符串。您需要使用jQuery的
removeAttr()


有人在这里谈论it/浏览器兼容性问题:

您也可以尝试
$(“#btnDele”).removeAttr('disabled')

在JQuery中,prop函数是执行此操作的正确方法

$('#btnDele').prop('disabled', false); //enabled
$('#btnDele').prop('disabled', true); //disabled
$('#btnDele').prop('disabled'); //returns true if disabled, false if enabled.
请参阅文档。

$(文档).ready(函数()){ $('#btnAdd')。单击(函数(){

}));
});

我假设缺少第二个
}
是一个输入错误?尝试使用removeAttr()而不是将属性的值设置为空string@MrOBrian不要在本机属性上使用
removeAttr
,因为一旦使用了,它们消失了,在DOM刷新之前您无法再次使用它们。@Ohgod为什么我以前使用
removeAttr
就是为了这个目的,而且它在我测试过的所有浏览器中都非常有效。如果需要再次禁用该元素,一个简单的
attr('disabled','disabled')
会将属性添加回元素+1以使用prop。别忘了提到它是为jQuery 1.6+Cheers@wirey提供的-忘了它是最近添加的!
$(function(){
     $('#btnAdd').click(function(e){
          $(this).removeAttr('disabled');
      });
 });
$('#btnDele').prop('disabled', false); //enabled
$('#btnDele').prop('disabled', true); //disabled
$('#btnDele').prop('disabled'); //returns true if disabled, false if enabled.
        // to enable the "remove" button
        // set 'disabled to false'
        $('#btnDele').attr('disabled','false');