[英]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.