[英]How to uncheck a group of checkbox in JQuery/JavaScript
我试图不选中全部和一组复选框(1、2、3) 。 例如,当未选中全部并选中1时 ,如果单击全部 ,则应选中1 ,反之亦然。
<input type="checkbox" name="checkAll" class="selectAll" /> All <br/> <input type="checkbox" name="checkuser" class="cb_box " /> 1 <input type="checkbox" name="checkuser" class="cb_box " /> 2 <input type="checkbox" name="checkuser" class="cb_box " /> 3
我以这种方式尝试过,但是没有用。 有什么建议吗?
$(function () {
$('.selectAll').click(function () {
$('input[name=checkuser]').attr('unchecked', $(this).attr('checked'));
});
功能prop
以及事件change
$('input[name="checkuser"]').prop('checked', $(this).is(':checked'));
$(function() { $('.selectAll').change(function() { $('input[name="checkuser"]').prop('checked', $(this).is(':checked')); }); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="checkbox" name="checkAll" class="selectAll" /> All <br/> <input type="checkbox" name="checkuser" class="cb_box " /> 1 <input type="checkbox" name="checkuser" class="cb_box " /> 2 <input type="checkbox" name="checkuser" class="cb_box " /> 3
$('.selectAll').click(function(){
$(':checkbox.cb_box').prop('checked', this.checked);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.