如何在jQuery中单击复选框时启用按钮?
如何在jQuery中单击复选框时启用按钮?
你可以这样做:
$("#checkBoxID").click(function() { $("#buttonID").attr("disabled", !this.checked); });
这在启用时启用,如果取消选中则再次禁用。 在jQuery中.attr("disabled", bool)
接受一个布尔值,所以你可以使用复选框的this.checked
DOM属性来保持这个。
$("#yourcheckboxid").click(function() { var checked_status = this.checked; if (checked_status == true) { $("#yourbuttonid").removeAttr("disabled"); } else { $("#yourbuttonid").attr("disabled", "disabled"); } });