答案 0 :(得分:0)
根据您的查询
如果我将检查主复选框,则已检查复选框要取消选中并取消选中要检查的复选框
试试吧,它会起作用
$('#master').on('click', function() {
if($(this).is(':checked')){
$('.branch').trigger('click');
}
});

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="checkbox" id="master">master</br>
<input type="checkbox" class="branch">1
<input type="checkbox" class="branch">2
<input type="checkbox" class="branch" checked>3
<input type="checkbox" class="branch">4
<input type="checkbox" class="branch">5
<input type="checkbox" class="branch" checked>6
<input type="checkbox" class="branch">7
<input type="checkbox" class="branch">8
<input type="checkbox" class="branch" checked>9
&#13;
答案 1 :(得分:0)
如果不触发所有输入,请尝试以下操作:
var masterCheckbox = jQuery("#master");
masterCheckbox.on("change", function()
{
if(masterCheckbox.is(":checked"))
{
var checkboxes = jQuery(".myCheckbox");
//get all checked and unchecked
var checked = checkboxes.filter(":checked");
var notchecked = checkboxes.filter(":not(:checked)");
checked.prop( "checked", false );
notchecked.prop( "checked", true );
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="checkbox" id="master" />
<br>
<input type="checkbox" class="myCheckbox" checked />
<input type="checkbox" class="myCheckbox" />
<input type="checkbox" class="myCheckbox" checked />
<input type="checkbox" class="myCheckbox" />
答案 2 :(得分:0)
使用prop()
方法
$('#master').on('click', function() {
$('.branch').each(function(){
$(this).prop('checked',!$(this).prop('checked'))
});
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<input type="checkbox" id="master">master</br>
<input type="checkbox" class="branch">1
<input type="checkbox" class="branch">2
<input type="checkbox" class="branch" checked>3
<input type="checkbox" class="branch">4
<input type="checkbox" class="branch">5
<input type="checkbox" class="branch" checked>6
<input type="checkbox" class="branch">7
<input type="checkbox" class="branch">8
<input type="checkbox" class="branch" checked>9
&#13;