选中6时禁用复选框-页面上具有复选框组的多个表单

问题描述:

我在页面上有多个表单,每个表单中都有30个左右的复选框(表单的数量取决于用户上传的内容).我需要把它安装在6个复选框被选中,其余该组未签被禁用的复选框英寸

I have multiple forms on a page, each have 30 or so checkboxes in them (the amount of forms varies depending upon the user upload). I need to have it setup when 6 checkboxes are checked the rest in that group of checkboxes that are not checked are disabled.

我可以很简单地用一种形式来解决问题-像这样:

I can sort out doing so with one form pretty simply -- something like:

$("input:checkbox").click(function() {
      var cbk = $("input:checkbox:checked").length >= 6;    
     $("input:checkbox").not(":checked").attr("disabled",cbk);

    }); 

但这最终会禁用所有表单的复选框.一直试图找到不同的方法来解决这个问题,但运气不佳.任何和所有帮助表示赞赏.谢谢.

But this ends up disabling the checkboxes for ALL the forms. Been trying to find different ways to sort this out but not having much luck. Any and all help is appreciated. Thanks.

请尝试以下操作:

$("input:checkbox").click(function() {
      var frm = $(this).closest("form").attr("id");//getting the id of nearest form
      var cbk = $("#" + frm + " input:checkbox:checked").length >= 6;    
     $("#" + frm + " input:checkbox").not(":checked").attr("disabled",cbk);

    }); 

逻辑是:查找被单击的复选框所在的表单.并将该表单用作过滤器.

logic is: Find the form in which that checkbox that was clicked resides. And use that form as a filter.

HTH