在jQuery中,如何使用元素检查和取消选中所有复选框? [英] In jQuery how do you check and uncheck all checkboxes using an element?
本文介绍了在jQuery中,如何使用元素检查和取消选中所有复选框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码。它使用LABEL元素检查页面上的所有复选框,该元素通常位于复选框的顶部。现在我如何使用相同的LABEL元素取消选中所有框?
I have the following code. It checks all the checkboxes on the page using the LABEL element which is usually on top of the checkboxes. Now how do I use the same LABEL element to uncheck all the boxes?
jQuery(document).ready(function($) {
var $checkBoxes = $('input[type="checkbox"]');
$('label').click(function() {
$checkBoxes.attr('checked', true);
});
});
推荐答案
使用:
$('.myCheckbox').prop('checked', true);
$('.myCheckbox').prop('checked', false);
这篇关于在jQuery中,如何使用元素检查和取消选中所有复选框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文