选中 6 个复选框时禁用复选框 - 页面上带有复选框组的多个表单
我在一个页面上有多个表单,每个表单中有 30 个左右的复选框(表单的数量根据用户上传的情况而变化)。当选中 6 个复选框时,我需要对其进行设置,而未选中的复选框组中的其余部分将被禁用。
我可以非常简单地用一种表单来完成此操作,例如:
$("input:checkbox").click(function() {
var cbk = $("input:checkbox:checked").length >= 6;
$("input:checkbox").not(":checked").attr("disabled",cbk);
});
但这最终会禁用所有表单的复选框。一直在尝试寻找不同的方法来解决这个问题,但运气不佳。感谢任何和所有的帮助。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请尝试这个:
逻辑是:找到被单击的复选框所在的表单。并使用该表单作为过滤器。
华泰
Please try this:
logic is: Find the form in which that checkbox that was clicked resides. And use that form as a filter.
HTH