//全选 全不选
 $('#checkAll').click(function () {
        //判断是否被选中
        var bischecked = $('#checkAll').is(':checked');
        var fruit = $('input[name="check"]');
        bischecked ? fruit.attr('checked', true) : fruit.attr('checked', false);
   });


//反选   遍历checkbox 如果当前为选中 就设置为 不选中 反之相同
    $("#tabVouchList tr").each(function () {
        if ($("td:eq(0) input[name='check']", $(this)).is(':checked')) {
            $(this).attr('checked', false);
        } else {
            $(this).attr('checked', true);
        }
    });

 

 

   //attr 可能会出现 第二次全选没反应的情况   prop 完美解决
   $("#checkall").bind("click", function () { 
         $("input[type='checkbox']").prop("checked", this.checked); 
   });

 

  

 

 

HTML table

        <table >
            <tr>
                <th>
                    <input type="checkbox" name="checkAll" />
                </th>
                <th>
                    行号
                </th>
                <th>
                    名称
                </th>
            </tr>
            <tr>
                <td>
                    <input type="checkbox" name="check" />
                </td>
                <td>
                    行号
                </td>
                <td>
                    名称
                </td>
            </tr>
        </table>

 

相关文章:

  • 2021-12-27
  • 2021-05-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-27
  • 2022-03-11
  • 2021-11-10
猜你喜欢
  • 2021-07-31
  • 2021-11-15
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
相关资源
相似解决方案