当前位置: 移动技术网 > IT编程>开发语言>Jquery > jQuery 实现复选框的全选与反选

jQuery 实现复选框的全选与反选

2019年01月07日  | 移动技术网IT编程  | 我要评论
    <script>
        //实现全选与反选
        $(".allandnotall").click(function () {
            if ($(this).prop("checked")) {
                $("input[id=inlinecheckbox1]:checkbox").each(function () {
                    $(this).prop("checked", true);
                });
            } else {
                $("input[id=inlinecheckbox1]:checkbox").each(function () {
                    $(this).prop("checked", false);
                });
            }
        });
        //当其中不勾选某一个选项的时候,则去掉全选复选框
        $(":checkbox[id=inlinecheckbox1]").click(function () {
            $(".allandnotall").prop('checked',
                $(":checkbox[id=inlinecheckbox1]").length == $(":checkbox[id=inlinecheckbox1]:checked").length);
        });
    </script>
<!-- 全选按钮 -->  
<label for="exampleinputemail2">全选</label>
 <input type="checkbox" class="allandnotall">
 <!-- 单选框 -->                
<td><input type="checkbox" value="{{ data.id }}" name="product_bound_id" id="inlinecheckbox1"></td>

 

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网