首页

jquery 关于table的全选与反选

seo达人

如果您想订阅本博客内容,每天自动发到您的邮箱中, 请点这里

控制表格的多选和反选,直接上代码,顺便安利一个小知识点:tr的底边框不显示的问题,解决办法是:table{border-collapse:collapse;}    


  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <style>
  6. *{margin:0;padding:0;}
  7. table{border-collapse:collapse}
  8. .detail_tb {width: 100%;border: 1px solid #ccc;}
  9. .detail_tb .fied_header {height: 38px;line-height: 38px;border-left: none;border-bottom: 1px solid #ccc;background-color: #ececec;}
  10. .detail_tb .fied_header th {text-align: center;border-right: 1px solid #ccc;color: #333;font-size: 14px;}
  11. .detail_tb .fied_header th input {vertical-align: middle;}
  12. .detail_tb tr {height: 38px;line-height: 38px;border-left: none;border-bottom: 1px solid #ccc;background-color: #fff;}
  13. .detail_tb tr td {text-align: center;border-right: 1px solid #ccc;color: #666;font-size: 14px;}
  14. .detail_tb tr td input {float: left;margin: 12px 5px 0 10px;}
  15. .detail_tb tr td span {float: left;}
  16. .detail_tb tr td select {display: inline-block;width: 90px;height: 24px;}
  17. </style>
  18. </head>
  19. <body>
  20. <table class="detail_tb" >
  21. <thead>
  22. <tr class="fied_header">
  23. <th width="65"><input type="checkbox" value="number" id="number"> 序号</th>
  24. <th width="110">孩子姓名</th>
  25. <th width="130">家长电话</th>
  26. <th width="110">介绍人孩子姓名</th>
  27. <th width="130">介绍人电话</th>
  28. <th width="150">报名时间</th>
  29. <th width="100">分组情况</th>
  30. <th width="100">拉新数量</th>
  31. <th width="100">是否签到</th>
  32. <th width="100">是否发奖</th>
  33. </tr>
  34. </thead>
  35. <tbody id="tbody">
  36. <tr>
  37. <td width="65"><input type="checkbox" value="" id="" ><span>1</span></td>
  38. <td width="110">张三</td>
  39. <td width="130">13888888888</td>
  40. <td width="110">李四</td>
  41. <td width="130">13888888888</td>
  42. <td width="150">2016/08/6 21:00</td>
  43. <td width="100">
  44. <select name="" id="">
  45. <option value="">未分组</option>
  46. <option value="">1</option>
  47. <option value="">2</option>
  48. </select>
  49. </td>
  50. <td width="100">33</td>
  51. <td width="100"></td>
  52. <td width="100">
  53. <select name="" id="">
  54. <option value=""></option>
  55. <option value="">奖品1</option>
  56. <option value="">奖品2</option>
  57. </select>
  58. </td>
  59. </tr>
  60. <tr>
  61. <td width="65"><input type="checkbox" value="" id=""><span>2</span></td>
  62. <td width="110">张四</td>
  63. <td width="130">13888888888</td>
  64. <td width="110">李四</td>
  65. <td width="130">13888888888</td>
  66. <td width="150">2016/08/6 21:00</td>
  67. <td width="100">
  68. <select name="" id="">
  69. <option value="">未分组</option>
  70. <option value="">1</option>
  71. <option value="">2</option>
  72. </select>
  73. </td>
  74. <td width="100">33</td>
  75. <td width="100"></td>
  76. <td width="100">
  77. <select name="" id="">
  78. <option value=""></option>
  79. <option value="">奖品1</option>
  80. <option value="">奖品2</option>
  81. </select>
  82. </td>
  83. </tr>
  84. <tbody>
  85. </table>
  86. <script src="https://cdn.bootcss.com/jquery/1.11.3/jquery.min.js"></script>
  87. <script type="text/javascript">
  88. // 全选和反选
  89. $("#number").click(function () {
  90. var isChecked = $("#number").prop("checked");
  91. $("#tbody input").prop("checked", isChecked);
  92. })
  93. // 单独选项控制全选
  94. $("#tbody input").click(function () {
  95. var allLength = $("#tbody input").length;
  96. var checkedLength = $("#tbody input:checked").length;
  97. if(allLength == checkedLength){
  98. $("#number").prop("checked",true);
  99. }else {
  100. $("#number").prop("checked",false);
  101. }
  102. });
  103. </script>
  104. </body>
  105. </html>



蓝蓝设计www.lanlanwork.com )是一家专注而深入的界面设计公司,为期望卓越的国内外企业提供卓越的UI界面设计、BS界面设计 、 cs界面设计 、 ipad界面设计 、 包装设计 、 图标定制 、 用户体验 、交互设计、 网站建设 平面设计服务


日历

链接

blogger

蓝蓝 http://www.lanlanwork.com

存档