jQuery - checkboxes like radiobuttons

前端 未结 9 1711
小鲜肉
小鲜肉 2020-12-01 11:07

I have group checkboxes and I like if this group have behaviour like radiobuttons with same name atribute.

Each checkbox has different name.

Only one can be

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-01 11:44

    var $unique = $('input.unique');
    
    $unique.click(function() {
    
     $checked = $(this).is(':checked') ; // check if that was clicked.
     $unique.removeAttr('checked'); //clear all checkboxes
     $(this).attr('checked', $checked); // update that was clicked.
    
    });
    

提交回复
热议问题