码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2019-01-06 12:00:42      阅读:156      评论:0      收藏:0      [点我收藏+]

标签:input   按钮   script   data   去掉   rop   单选   amp   type   

    <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>

 

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

标签:input   按钮   script   data   去掉   rop   单选   amp   type   

原文地址:https://www.cnblogs.com/xshan/p/10227477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!