I want to disable all unchecked checkboxes of a class when one of the checkboxes in that class is checked so i tried this
if ((($('input[type=checkbox]:checked.classname)).length)==1) {
$('.classname').not(':checked').each(function(){
$(this).attr('disabled','disabled');
});
and i also tried this one
$("input[type=checkbox]."+aclass).not(':checked').attr('disabled',true);
This code doesnt d开发者_如何学Cisable any of the checkboxes although i am getting the length right using this selector?
Try this:
$('.test').change(function(){
if($('input.test').filter(':checked').length == 1)
$('input.test:not(:checked)').attr('disabled', 'disabled');
else
$('input.test').removeAttr('disabled');
});
JSFiddle
This subject has already been beaten to death. Consensus was use of radio buttons with a "none" option of some sort. This way you avoid coding new functionality into controls for which users hold certain expectations.
精彩评论