Jquery how to count checked and disable checkboxes

后端 未结 7 1476
有刺的猬
有刺的猬 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:18

    $('table input[type="checkbox"]').click(function(){
        var countcheck = $('table input[type="checkbox"]:checked').length;
        if(countcheck > 4) {
            $("table input:checkbox:not(:checked)").attr("disabled", true);
        }else
        {
            $("table input:checkbox").attr("disabled", false);
        }
    });
    

    Working Example: http://jsfiddle.net/mtYtW/48/

    NOTE: This code will enable the checkboxes if you deselect one of the five!

提交回复
热议问题