Html jQuery从单独的特定复选框中取消选中div中的复选框
有两个单独的div:check_one和check_two。 选中一个有4个框,选中二个有1个框 如果选中check_two div中的复选框,则应取消选中第一个div中的所有复选框,即check_one。这有点让人困惑,但这正是我想要做的 HTML::Html jQuery从单独的特定复选框中取消选中div中的复选框,html,jquery,checkbox,Html,Jquery,Checkbox,有两个单独的div:check_one和check_two。 选中一个有4个框,选中二个有1个框 如果选中check_two div中的复选框,则应取消选中第一个div中的所有复选框,即check_one。这有点让人困惑,但这正是我想要做的 HTML:: <div id="check_one"> <label>Stuff 1</label> <input name="" type="checkbox" value="" id="group1" c
<div id="check_one">
<label>Stuff 1</label> <input name="" type="checkbox" value="" id="group1" checked="checked"><br>
<label>Stuff 2</label> <input name="" type="checkbox" value="" id="group1" checked="checked"><br>
<label>Stuff 3</label> <input name="" type="checkbox" value="" id="group1" checked="checked"><br>
<label>Stuff 4</label> <input name="" type="checkbox" value="" id="group1" checked="checked">
</div>
<br>
<div id="check_two">
<label>Undo</label> <input name="uncheckMe" type="checkbox" value="" id="group2">
</div>
试试这个:
$("input[name='uncheckMe']").change(function(){
if ($(this).is(":checked")){
$("#check_one input").removeAttr("checked");
}
});
还有一个jsiddle:我为此创建了一个jsiddle 您缺少Change()中的函数:
下次,请关闭您的
,id是整个html页面的唯一标识符,因此您的“group1”id违反了此规则。此外,您必须在属性选择器后面加引号:$('input[name=“uncheckMe”]”)。change()@JofryHS:
不建议用于html<很好。你看,我把它钉死了。谢谢你!
$("input[name='uncheckMe']").change(function(){
if ($(this).is(":checked")){
$("#check_one input").removeAttr("checked");
}
});
$('input[name=uncheckMe]').change(function(){
$("#check_one > input").each(function(i) {
if ($(this).is(":checked")) {
$(this).removeAttr("checked");
}
});
});