简体   繁体   English

选中一个复选框后如何删除其他复选框上的复选框

[英]how to remove check on other checkboxes when one checkbox is checked

when i click on one checkbox I want to remove the other checkboxes if they are checked using jquery. 当我单击一个复选框时,如果要使用jquery选中其他复选框,则要删除其他复选框。 Here is my code 这是我的代码

  <div class="toggle-two">
    <div>Novice</div>
    <label class="switch">
      <input class="switch" value="switch-novice" type="checkbox"/>
      <span class="slider round"></span>
    </label>
  </div>

  <div class="toggle-three">
    <div>Intermediate</div>
    <label class="switch">
      <input class="switch" value="switch-intermediate"  type="checkbox" />
      <span class="slider round"></span>
    </label>
  </div>

  <div class="toggle-four">
    <div>Expert</div>
    <label class="switch">
      <input class="switch" value="switch-expert" type="checkbox" />
      <span class="slider round"></span>
    </label>
  </div>

and my jquery 和我的jQuery

  $(".switch").change(function(e) {
    switch (e.target.value) {
      case "switch-novice":
        if (this.checked) {
          $(":checkbox[value=switch-intermediate]").removeAttr("Checked");
                    $(":checkbox[value=switch-expert]").removeAttr("Checked");
        }
        break;
      case "switch-intermediate":
        break;
      case "switch-expert":
        break;
      default:
    }
  });

I have also tried , can someone show me how to do it. 我也尝试过,有人可以告诉我该怎么做。

$(":checkbox[value=switch-expert]").attr('checked', false)

full code here jfiddle 完整的代码在这里jfiddle


$(":checkbox").click(function(e) {
    $(":checkbox[value!="+$(this).attr('value')+"]").attr('checked', null);
});

Use radio buttons for this interface, not checkboxes. 使用单选按钮显示此界面,而不使用复选框。 They implement this behavior automatically for groups of radio buttons which share the same name . 它们自动为共享相同name的单选按钮组实现此行为。

 <label> <input type="radio" name="input-name" value="1"> Option One </label> <br> <label> <input type="radio" name="input-name" value="2"> Option Two </label> <br> <label> <input type="radio" name="input-name" value="3"> Option Three </label> 

$(":checkbox").click(function(e) {
    $(":checkbox").prop('checked', false)
    $(e.target).prop('checked', true);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从复选框数组中检查至少一个复选框,并且复选框中的文本区域不为空白,且其值为“ other”? - How to check at least one checkbox is checked from the array of checkboxes and the text area is not blank on checkbox with value “other” is checked? 选中一个复选框后,选中所有其他复选框 - Check all other checkboxes when one is checked 当组中的一个复选框被选中时,禁用并取消选中所有其他复选框 - When one checkbox is checked in a group, disable & uncheck all other checkboxes 如何检查多个复选框中是否选中了至少一个复选框? - How to check that at least one checkbox is checked in multiple checkboxes? 如何选中其下面的所有复选框后选中复选框? - How to check a checkbox when all the checkboxes below it are checked? 当选中一个div中的复选框时,如何取消取消另一个div中的复选框 - How to unckeck checkboxes in another div when checkbox in one div is checked 在检查其他3个复选框时,如何检查和禁用复选框 - How to check and disable a checkbox, when other 3 checkbox are checked, in Angular 选中其他复选框时如何取消选中复选框? - How to uncheck checkboxes when check other one? 如果勾选了一个复选框,如何取消选中所有复选框? - How to uncheck all checkboxes, if one checkbox checked? 如果选中其他复选框,则禁用复选框 - disable checkbox if other checkboxes is checked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM