jquery实现全选 反选 取消
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <input type="button" value="全选" οnclick="checkAll()"> <input type="button" value="反选" οnclick="reserveAll()"> <input type="button" value="取消" οnclick="cancleAll()"> <table border="1"> <thread> <th>选项</th> <th>姓名</th> <th>学号</th> </thread> <tbody> <tr> <td><input type="checkbox"></td> <td>大眼侠</td> <td>1001</td> </tr> <tr> <td><input type="checkbox"></td> <td>大眼侠</td> <td>1001</td> </tr> <tr> <td><input type="checkbox"></td> <td>大眼侠</td> <td>1001</td> </tr> <tr> <td><input type="checkbox"></td> <td>大眼侠</td> <td>1001</td> </tr> <tr> <td><input type="checkbox"></td> <td>大眼侠</td> <td>1001</td> </tr> </tbody> </table> <script src="jquery1.9.js"></script> <script> function checkAll() { $(":checkbox").prop("checked",true); } function cancleAll() { $(":checkbox").prop('checked',false); } function reserveAll() { $(":checkbox").each(function () { var v=$(this.checked)? false:true; $(this).prop('checked',v); }) } </script> </body> </html>