爱程序网

Jq 遍历 全选 全不选 反选

来源: 阅读:

//全选 全不选
 $('#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);
        }
    });

 HTML table

        <table id="tabVouchList">
            <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>

 

关于爱程序网 - 联系我们 - 广告服务 - 友情链接 - 网站地图 - 版权声明 - 人才招聘 - 帮助