如果你对该文章中的内容有疑问/不解,可以点击此处链接提问
要注明问题和此文章链接地址 点击此处跳转
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script class="jquery library" src="/js/sandbox/jquery/jquery-1.8.2.min.js" type="text/javascript"></script> <title> RunJS 演示代码 </title> <style> table{ width:100%; border:1px solid black; border-collapse:collapse; } td th{ border:1px solid black; } </style> <script> $(document).ready(function(){ $("tr :button:nth-child(1)").click(function(){ $(this).closest("tr").find(":checkbox").prop("checked",true); }); $("tr :button:nth-child(2)").click(function(){ $(this).closest("tr").find(":checkbox").prop("checked",false); }); }); </script> </head> <body> <table> <tr> <th> no </th> <th> 1 </th> <th> 2 </th> <th> 3 </th> </tr> <tr> <td> 11 </td> <td> <label> <input type="checkbox" /> 11 </label> <label> <input type="checkbox" /> 11 </label> <label> <input type="checkbox" /> 11 </label> <label> <input type="checkbox" /> 11 </label> <label> <input type="checkbox" /> 11 </label> <label> <input type="checkbox" /> 11 </label> </td> <td> 11 </td> <td> <button> 全选 </button> <button> 取消 </button> </td> </tr> </table> </body> </html> |
修改(版本问题)
1 2 3 |
.attr("checked",true); 改成 .prop("checked",true); |