以下代码工作正常,但有 1 个错误
$(document).ready(
function() {
$("#myCheckboxes input[type='checkbox']").change(function() {
var checked = $("#myCheckboxes input[type='checkbox']:checked").length;
if(checked == 4){
$("#myCheckboxes input[type='checkbox']")
.attr('disabled',true)
.find(':checked')
.attr('disabled',false)
} else {
$("#myCheckboxes input[type='checkbox']").attr('disabled',false);
}
});
});
选择变为 4 后,所有复选框都将被禁用,甚至选定的复选框也会被禁用,但我不想禁用选定的复选框。
谢谢
最佳答案
试试这个
$("#myCheckboxes :checkbox:not(:checked)").attr('disabled', true)
而不是
$("#myCheckboxes input[type='checkbox']")
.attr('disabled',true)
.find(':checked')
.attr('disabled',false)
关于jquery - 禁用所有复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1560546/