jquery 复选框操作-prop()的使用
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script src="jquery-3.3.1.js"></script>
<script>
$(function () {
$('#btnSelectAll').click(function () {
$('div :checkbox').prop('checked', true);
});
$('#btnNotSelectAll').click(function () {
$('div :checkbox').prop('checked', false);
});
$('#btnFX').click(function () {
$('div :checkbox').each(function (index, ele) {
$(ele).prop('checked', !$(ele).prop('checked'));
});
});
})
</script>
</head>
<body>
<input type="button" name="name" value="全选" id="btnSelectAll" />
<input type="button" name="name" value="全不选" id="btnNotSelectAll" />
<input type="button" name="name" value="反选" id="btnFX" />
<div>
<input type="checkbox" name="name" value="1" />1
<input type="checkbox" name="name" value="2" />2
<input type="checkbox" name="name" value="3" />3
<input type="checkbox" name="name" value="4" />4
<input type="checkbox" name="name" value="4" />5
</div>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script src="jquery-3.3.1.js"></script>
<script>
$(function () {
$('#btnSelectAll').click(function () {
$('div :checkbox').prop('checked', true);
});
$('#btnNotSelectAll').click(function () {
$('div :checkbox').prop('checked', false);
});
$('#btnFX').click(function () {
$('div :checkbox').each(function (index, ele) {
$(ele).prop('checked', !$(ele).prop('checked'));
});
});
})
</script>
</head>
<body>
<input type="button" name="name" value="全选" id="btnSelectAll" />
<input type="button" name="name" value="全不选" id="btnNotSelectAll" />
<input type="button" name="name" value="反选" id="btnFX" />
<div>
<input type="checkbox" name="name" value="1" />1
<input type="checkbox" name="name" value="2" />2
<input type="checkbox" name="name" value="3" />3
<input type="checkbox" name="name" value="4" />4
<input type="checkbox" name="name" value="4" />5
</div>
</body>
</html>