<!doctype html>
<meta charset= "UTF-8" >
<title>Document</title>
<body>
<ul id= "List" >
<li><label><input type= "checkbox" value= "1" > 1. Where did the time go </label></li>
<li><label><input type= "checkbox" value= "2" > 2. Sky </label></li>
<li><label><input type= "checkbox" value= "3" > 3. Really love you </label></li>
<li><label><input type= "checkbox" value= "4" > 4. No more hesitation </label></li>
<li><label><input type= "checkbox" value= "5" > 5. Glorious years </label></li>
<li><label><input type= "checkbox" value= "6" > 6. Like you </label></li>
</ul>
<input type= "checkbox" id= "All" >
<input type= "button" value= "Select All" class= "btn" id= "SelectAll" >
<input type= "button" value= "All not selected" class= "btn" id= "Unselect" >
<input type= "button" value= "Reverse Selection" class= "btn" id= "reverse" >
<input type= "button" value= "Get all Values selected" class= "btn" id= "GetValue" >
<script src= "Jquery-1.11.3.js" ></script>
<script>
$ (function () {
Select All or do not select all
$ ("#all"). Click (function () {
if (this.checked) {
$ ("#list: CheckBox"). attr ("Checked", true);
}else{
$ ("#list: CheckBox"). attr ("checked", false);
}
});
Select All
$ ("#selectAll"). Click (function () {
$ ("#list: CheckBox, #all"). attr ("Checked", true);
});
All do not choose
$ ("#unSelect"). Click (function () {
$ ("#list: CheckBox, #all"). attr ("checked", false);
});
Inverse selection
$ ("#reverse"). Click (function () {
$ ("#list: CheckBox"). each (function () {
$ (this). attr ("Checked",!$ (This). attr ("checked"));
});
Allchk ();
});
Set the Select all check box
$ ("#list: CheckBox"). Click (function () {
Allchk ();
});
Gets the value of the selected option
$ ("#getValue"). Click (function () {
var valarr = new Array;
$ ("#list: checkbox[checked]"). each (function (i) {
Valarr[i] = $ (this). Val ();
});
var vals = Valarr.join (', ');
alert (Vals);
});
});
function Allchk () {
var chknum = $ ("#list: CheckBox"). Size ();//total number of options
var chk = 0;
$ ("#list: CheckBox"). each (function () {
if ($ (this). attr ("checked") ==true) {
chk++;
}
});
if (CHKNUM==CHK) {//Select all
$ ("#all"). attr ("Checked", true);
}else{//not select all
$ ("#all"). attr ("checked", false);
}
}
</script>
</body>
Checkbook Select all/Reverse selection/No selection