开发者

Disable all unchecked checkboxes of a class in jquery

开发者 https://www.devze.com 2023-03-21 12:16 出处:网络
I want to disable all unchecked checkboxes of a class when one of the checkboxes in that class is checked so i tried this

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消