The instance code is as follows:
<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<body>
<input type= "button" value= "Select All"/>
<input type= "button" value= "Reverse selection"/>
<input type= "button" value= "Cancel"/>
<table border= "1" >
<thead></thead>
<tbody id= "TB1" >
<tr>
<td><input type= "checkbox"/></td>
<td>11</td>
</tr>
<tr>
<td><input type= "checkbox"/></td>
<td>22</td>
</tr>
<tr>
<td><input type= "checkbox"/></td>
<td>33</td>
</tr>
</tbody>
</table>
<script src= "Jquery-3.1.0.min.js" type= "Text/javascript" ></script>
<script type= "Text/javascript" >
function Checkall () {
$ (' #tb1 '). Find (': CheckBox '). attr (' checked ', ' checked ');
$ (' #tb1 '). Find (': CheckBox '). Prop (' checked ', true);
attr and prop differences, attr is set for all label properties, prop is a special property setting for check and Radio checkboxes
}
function Checkreverse () {
Find, if selected, cancel; unchecked, select;
$ (' #tb1 '). Find (': CheckBox '). each (function () {
$ (this) each check box
$ (this). Prop (), if selected, true, otherwise false
attr If selected; checked,checked=checked
if ($ (this). Prop (' checked ')) {
$ (this). Prop (' checked ', false);
}else{
$ (this). Prop (' checked ', true);
}
});
}
function Checkcancel () {
$ (' #tb1 '). Find (': CheckBox '). Removeattr (' checked ');
$ (' #tb1 '). Find (': CheckBox '). Prop (' checked ', false);
}
</script>
</body>
This article from "Flat Light is true" blog, please be sure to keep this source http://ucode.blog.51cto.com/10837891/1847218
CheckBox full selection, reverse selection, cancellation