实现全选与反选
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> 点击:<input type="checkbox" id="checkAll" name="checkAll"/><br> <input type='checkbox' name='checkItem' class='btnSelect' /><br> <input type='checkbox' name='checkItem' class='btnSelect'/><br> <input type='checkbox' name='checkItem' class='btnSelect' /><br> <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-2.1.4.min.js"></script> <script> $("#checkAll").click(function () { if (this.checked) { $("input[name='checkItem']:checkbox").each(function () { $(this).attr("checked", true); }); } else { $("input[name='checkItem']:checkbox").each(function () { $(this).attr("checked", false); }); } }); </script> </body> </html>