<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>jquery正反选</title>
</head>
<body>
<button οnclick='selectall()'>全选</button>
<button οnclick="cancel()">取消</button>
<button οnclick="reverse()">反选</button>
<table border="1">
<tr>
<td><input type="checkbox"></td>
<td>111</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>222</td>
</tr>
<tr>
<td><input type="checkbox"></td>
<td>333</td>
</tr>
</table>
<script src="/static/jquery.min.js"></script>
<script>
function selectall() {
$(':checkbox').each(function () {
$(this).prop('checked', true)
})
}
function cancel() {
$(':checkbox').each(function () {
$(this).prop('checked', false)
})
}
function reverse() {
$(':checkbox').each(function () {
if ($(this).prop('checked')){
$(this).prop('checked', false)
}
else {
$(this).prop('checked', true)
}
})
}
</script>
</body>
</html>