复选框全选反选问题

<script type="text/javascript">
    $(function(){
        $("#dispatch_btn").click(function(){
            var array = [];
            $('input[name=chk_list]').each(function(){
                if($(this).is(':checked'))
                    array.push($(this).parent().next().val());
            });
            console.log(array);
        });
    });
    function allCheck(e){
        console.log("%o",e);
        if($("#chkall").is(':checked')){
            $('input[name=chk_list]').each(function() {
                console.log(this);
                $(this).prop("checked", true);
            });
        } else {
            $('input[name=chk_list]').each(function() {
                console.log(this);
                $(this).removeAttr("checked");
            });
        }
    }
</script>

springmvc控制器端可直接用String[]接受数组参数

注意点:

$(this).attr("checked",true)这种方式有可能只有一次生效,原因不明

posted @ 2017-06-21 09:59  倚天剑雨  阅读(172)  评论(0编辑  收藏  举报