选中复选框时,请禁用其他相同值的复选框 [英] When Checkbox checked make other same value checkboxes disabled

查看:90
本文介绍了选中复选框时,请禁用其他相同值的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

选中一个复选框后如何禁用其他相同值的复选框.

How to make other same value checkbox disabled when one checked.

<input type='checkbox' name='check[]' value = '1'>
<input type='checkbox' name='check[]' value = '2'>
<input type='checkbox' name='check[]' value = '1'>
<input type='checkbox' name='check[]' value = '2'>

推荐答案

如果您只想禁用具有相同值的另一个复选框,而不要禁用被选中的复选框,则类似的事情应该起作用:

Something like that should work if you want to disable only the other checkbox with the same value and not the checkbox who is checked :

$("input[name='check[]']").on('click', function() {
  var val = $(this).val();
  var parent = $(this);
  $("input[value='"+val+"']").each(function() {
    $(this).not(parent).attr('disabled', parent.is(':checked'));
  });
})

演示

这篇关于选中复选框时,请禁用其他相同值的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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