jQuery Realizes All and Counter Checking of Check Boxes

  • 2021-07-15 06:57:53
  • OfStack

Not much to say, please look at the code


<!DOCTYPE html>
<html lang="en">
<head>
 <meta charset="UTF-8">
 <title>Document</title>
</head>
<body>
 <form>
 <label for="apple"> Apple </label>
 <input type="checkbox" name="apple">
 <label for="banana"> Banana </label>
 <input type="checkbox" name="banana">
 <label for="orange"> Orange </label>
 <input type="checkbox" name="orange">
 <input type="button" value=" All selection " onclick="allPick()">
 <input type="button" value=" Do not choose at all " onclick="unAllPick()">
 <input type="button" value=" Reversal " onclick="inverserPick()">
 </form>
 <script src="http://cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
 <script>
 //  All selection 
 function allPick() {
  $("[type=checkbox]:checkbox").each(function () {
  this.checked = true;
  })
 }
 //  Do not choose at all 
 function unAllPick() {
  $("[type=checkbox]:checkbox").each(function () {
  this.checked = false;
  })
 }
 //  Reversal 
 function inverserPick() {
  $("[type=checkbox]:checkbox").each(function () {
  this.checked = !this.checked;
  })
 }
 </script>
</body>
</html>

Related articles: