首页 > 代码库 > 复选框作为按钮 实现全选/不全选

复选框作为按钮 实现全选/不全选

  $(function () {
            $("#checkAll").click(function () {
                $(‘input[name="infoids[]"]‘).attr("checked", this.checked);
            });
            var $subBox = $("input[name=‘infoids[]‘]");
            $subBox.click(function () {
                $("#checkAll").attr("checked", $subBox.length === $("input[name=‘infoids[]‘]:checked").length ? true : false);
            });
        });

 

 

 <table class="datalist">
                    <tr>
                        <td class="rv_td3">用户昵称</td>
                        <td class="rv_td4">评价内容</td>
                        <td class="rv_td5">评价时间</td>
                        <td class="rv_td7">是否显示
                            <input type="checkbox" id="checkAll" name="checkAll" value="http://www.mamicode.com/1"/>
                        </td>
                    </tr>
                    <volist name="list" id="vo">
                        <tr>
                            <td class="rv_td3">{$vo.nick_name}</td>
                            <td class="rv_td4">{$vo.review_content}</td>
                            <td class="rv_td5">{$vo.review_time}</td>
                            <td class="rv_td7">
                                <if condition="($vo.appear eq 1)">
                                    <input type="checkbox" id="infoids" name="infoids[]" value="http://www.mamicode.com/{$vo.id}" checked/>
                                    <else/>
                                    <input type="checkbox" id="infoids" name="infoids[]" value="http://www.mamicode.com/{$vo.id}"/>
                                </if>
                            </td>
                        </tr>
                    </volist>
                </table>