2010-08-25 81 views

回答

42

你可以这样说:

$("#checkBoxID").click(function() { 
    $("#buttonID").attr("disabled", !this.checked); 
}); 

这使得检查时,如果你取消再次关闭。在jQuery .attr("disabled", bool)需要一个布尔值,所以你可以使用复选框的this.checkedDOM属性保持这个很短的时间。

+6

对否定布尔值+1,这是一个不够用的简单技术,IMO。哦,而不是使用* .is(“:checked”)*,也是;-) – 2010-08-25 12:22:41

+1

从jQuery 1.6开始,建议使用.prop()方法代替它(http://api.jquery.com/attr /)。 – Eirik 2016-04-14 12:18:14

2
$("#yourcheckboxid").click(function() { 
    var checked_status = this.checked; 
    if (checked_status == true) { 
     $("#yourbuttonid").removeAttr("disabled"); 
    } else { 
     $("#yourbuttonid").attr("disabled", "disabled"); 
    } 
}); 
相关问题