组合框的全选、全不选以及反选问题

来源:互联网 发布:淘宝怎么拿货 编辑:程序博客网 时间:2024/06/08 10:32
<form action="" method="post">              <input type="checkbox" name="c" id="" value="1" />1    <input type="checkbox" name="c" id="" value="2" />2    <input type="checkbox" name="c" id="" value="4" />3    <input type="checkbox" name="c" id="" value="3" />4    <input type="button" value="提交"/>    <input type="button" name="" id="checkedall" value="全选" />    <input type="button" name="" id="checkedno" value="全不选" />    <input type="button" name="checkedrev" id="" value="反选" />     <div>    <input type="checkbox" name="checked" id="checkedAll" value="" /><label for="checked"   >全选/全不选</label>    </div></form>
//全选        $(function(){            $('#checkedall').click(function(){                $('[name=c]:checkbox').prop("checked",true);            })//全不选            $('#checkedno').click(function(){                $('[name=c]').prop('checked',false);            })        });//反选        $('#checkedrev').click(function(){                $('input:checkbox[name=c]').each(function(){                    $(this).prop('checked',!$(this).prop('checked'));                })            })  //也可以使用原生js$('#checkedrev').click(function(){                $('input:checkbox[name=c]').each(function(){                    this.checked=!this.checked;                })            })  //全选、全不选$('#checked').click(function(){    var flag=$(this).prop('checked');    $("input[name='c']).prop('checked',flag);})

转载自《锋利的JQuery》

原创粉丝点击