<!doctype html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Document</title> <script src="./js/jquery.min.js"></script> </head> <body> <form action="" method="post"> <input type="checkbox" name="like[]" class="checkList" value=<?php echo 111;?>>ball<br> <input type="checkbox" name="like[]" class="checkList" value=2>study<br> <input type="checkbox" name="like[]" class="checkList" value=3>game<br> <input type="checkbox" name="like[]" class="checkAll" value=4>全选/全不选 </form> </body> <script> $(".checkAll").click(function() { var flag1 = $(".checkList").attr("checked") == "checked" ? 1 : 2; if (flag1 == 1) { window.location.reload(); } //flag为<input type="checkbox" name="like[]" class="checkAll" value=4>全选/全不选 的标志 //它全选 flag = 2; 它全不选 flag = 1; var flag = $(this).attr("checked") == "checked" ? 1 : 2; if (flag == 2) { //全选 $(this).attr("checked", "checked"); $(".checkList").attr("checked", "checked"); } else { //否则全不选 $(this).removeAttr("checked"); $(".checkList").removeAttr("checked"); } }); </script> </html>
时间: 2024-10-20 22:11:03