![](/img/trans.png)
[英]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?
[英]how to remove check on other checkboxes when one checkbox is checked
当我单击一个复选框时,如果要使用jquery选中其他复选框,则要删除其他复选框。 这是我的代码
<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>
和我的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:
}
});
我也尝试过,有人可以告诉我该怎么做。
$(":checkbox[value=switch-expert]").attr('checked', false)
完整的代码在这里jfiddle
$(":checkbox").click(function(e) {
$(":checkbox[value!="+$(this).attr('value')+"]").attr('checked', null);
});
使用单选按钮显示此界面,而不使用复选框。 它们自动为共享相同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.