如何在单击一个复选框时禁用其他复选框? [英] How to disable other checkbox on click of one check box?

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

问题描述

我有一组同名的复选框,我需要的是当我单击其中任何一个时,其他复选框必须被禁用.我应该如何在它上面应用 Javascript?

I have a group of check boxes with same name, what I need is when I click any one of them, other checkboxes must get disabled. how should I apply Javascript over it?

<input type="checkbox" name="finallevelusers[]" value="1"/>
<input type="checkbox" name="finallevelusers[]" value="1"/>
<input type="checkbox" name="finallevelusers[]" value="1"/>
<input type="checkbox" name="finallevelusers[]" value="1"/>

请帮忙...

推荐答案

<script type="text/javascript">
for (i=0; i<document.test.finallevelusers.length; i++){
if (document.test.finallevelusers[i].checked !=true)
  document.test.finallevelusers[i].disabled='true';
}
</script>

当用户取消选中复选框时,您可能希望它们再次启用

probably you want them enabled again when user uncheck the checkbox

for (i=0; i<document.test.finallevelusers.length; i++){
    if (document.test.finallevelusers[i].disabled ==true)
      document.test.finallevelusers[i].disabled='false';
    }

这篇关于如何在单击一个复选框时禁用其他复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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