选中6时禁用复选框-页面上具有复选框组的多个表单 [英] Disable checkboxes when 6 are checked -- multiple forms on page with checkbox groups

查看:74
本文介绍了选中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

这篇关于选中6时禁用复选框-页面上具有复选框组的多个表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆