Jquery how to count checked and disable checkboxes

后端 未结 7 1437
有刺的猬
有刺的猬 2021-02-15 12:29

I am trying to disable all unchecked checkboxes when there are 5 checked checkboxes.

My code is not working here it is: http://jsfiddle.net/mtYtW/18/

My Jquery:

7条回答
  •  感动是毒
    2021-02-15 13:20

    $(':checkbox').bind('click', function(){
        if($(':checkbox:checked').length >= 5) {
            $(':checkbox').not(':checked').prop('disabled', true);
        } else {
            $(':checkbox').not(':checked').prop('disabled', false);
        }
    });
    

    Note that prop is jQuery 1.6 exclusive. In case of jQuery < 1.6 use attr.

提交回复
热议问题