复选框:选中另一个时取消选中
Checkbox: uncheck when on another is checked
我正在尝试使用此函数在选中另一个复选框时取消选中复选框:
<script>
$('input.unchecked').on('change', function() {
$('input.unchecked').not(this).prop('checked', false);
});
</script>
<script>
$("#checkboxID").change(function(){
$("#tableID tr.rowEG").toggle(!this.checked);
});
$("#checkbox1OG").change(function(){
$("#tableID tr.row1OG").toggle(!this.checked);
});
$("#checkbox2OG").change(function(){
$("#tableID tr.row2OG").toggle(!this.checked);
});
$("#checkbox3OG").change(function(){
$("#tableID tr.row3OG").toggle(!this.checked);
});
</script>
但不起作用,因为当您选中另一个复选框时,表格内容会消失。
这是 HTML 代码:
<form class="filter">
<input type="checkbox" id="checkboxID" class="unchecked"> EG
<input type="checkbox" id="checkbox1OG" class="unchecked"> 1.OG
<input type="checkbox" id="checkbox2OG" class="unchecked"> 2.OG
<input type="checkbox" id="checkbox3OG" class="unchecked"> 3.OG
</form>
在这里我想使用它:
http://develop.nowcommu.myhostpoint.ch/table-test.html
有什么想法吗?
编辑:也许这就是问题所在?
<script>
$("#checkboxID").change(function(){
$("#tableID tr.rowEG").toggle(!this.checked);
});
$("#checkbox1OG").change(function(){
$("#tableID tr.row1OG").toggle(!this.checked);
});
$("#checkbox2OG").change(function(){
$("#tableID tr.row2OG").toggle(!this.checked);
});
$("#checkbox3OG").change(function(){
$("#tableID tr.row3OG").toggle(!this.checked);
});
</script>
这是一个不需要脚本的简单解决方案。
input{
display:none;
}
label{
width:25px;
height:25px;
font-size:16px;
cursor:pointer;
position:relative;
padding-left: 30px;
}
label ~ label {
margin-left: 40px;
}
label:before,
label:after{
top: 0;
left: 0;
position:absolute;
height:15px;
width:15px;
content:' ';
border-radius: 2px;
border: 1px #3a3a3a solid;
font-weight: bold;
}
input:checked + label:after{
top: -2px;
left: 2px;
content: ''2713';
border: none;
}
<form class="filter">
<input type="radio" name="radio" id="radio"><label for="radio"> EG </label>
<input type="radio" name="radio" id="radio1"><label for="radio1"> 1.OG </label>
<input type="radio" name="radio" id="radio2"><label for="radio2"> 2.OG </label>
<input type="radio" name="radio" id="radio3"><label for="radio3"> 3.OG </label>
</form>
看小提琴:https://jsfiddle.net/61eywpzg/
.HTML
<form class="filter">
<input type="checkbox" id="checkboxID" class="unchecked"> EG
<input type="checkbox" id="checkbox1OG" class="unchecked"> 1.OG
<input type="checkbox" id="checkbox2OG" class="unchecked"> 2.OG
<input type="checkbox" id="checkbox3OG" class="unchecked"> 3.OG
</form>
<script src="https://code.jquery.com/jquery-2.2.0.min.js"></script>
jQuery
$('input.unchecked').on('change', function() {
$('input.unchecked').not(this).prop('checked', false);
});
尝试以下代码片段:
$('.unchecked').click(function(){
$(this).siblings().prop("checked",false)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<form class="filter">
<input type="checkbox" id="checkboxID" class="unchecked"> EG
<input type="checkbox" id="checkbox1OG" class="unchecked"> 1.OG
<input type="checkbox" id="checkbox2OG" class="unchecked"> 2.OG
<input type="checkbox" id="checkbox3OG" class="unchecked"> 3.OG
</form>
您可以使用单选按钮而不是复选框。为此,请将输入的类型更改为无线电,例如:
<input type="radio" id="checkboxID" class="unchecked">
相关文章:
- 如何从另一个处理程序内部取消JavaScript事件处理程序函数的执行
- 当选中另一个复选框时,如何取消选中该复选框
- 在简单模式中,取消单击时不会调用onClose事件..当我在simple-modal上加载另一个jquery对话框时
- 取消选中某个复选框将取消选中另一个复选框
- Javascript:通过另一个函数取消提示
- 如何在选中数组中的另一个复选框时使用 jquery 取消选中复选框
- 取消绑定 e.prevent默认 从另一个函数转发到链接单击
- 如果用户发送另一个请求,请使用 .abort() 取消现有的 ajax 请求
- 当从第一个选项中选择一个选项时,如何取消隐藏另一个选择字段
- 如何在 Firefox 中单击另一个复选框时一次取消选择多个复选框
- 如果另一个复选框使用 javascript 选中,请取消选中另一个复选框
- 复选框:选中另一个时取消选中
- Javascript:当一个复选框被取消选中时,取消选中另一个复选复选框
- 单击“取消”按钮,显示另一个文本字段的值
- 如何在选中另一个复选框时取消选中一组复选框
- 选中复选框(取消)时显示另一个文本
- onchange javascript点击事件取消了另一个
- 单击一个按钮可取消jQuery中另一个(外部)按钮的单击事件
- AngularJS:如何在选择另一个跨度时取消选择跨度
- Javascript 返回 false;不会取消另一个 .submit jQuery 调用的表单提交