js 判断判断多选表单checkbox

 

html代码

<input type="checkbox" class="ace auth_id" name="ckb[]" value="{!! $item->id !!}"/>
<input type="checkbox" class="ace auth_id" name="ckb[]" ........... />
<input type="checkbox" class="ace auth_id" name="ckb[]" ........... />
<input type="checkbox" class="ace auth_id" name="ckb[]" ........... />
<input type="checkbox" class="ace auth_id" name="ckb[]" ........... />
<button id="pass" type="submit" class="btn btn-sm btn-primary ">通过</button>
<button id="deny" type="submit" class="btn btn-sm btn-primary ">失败</button>

 

js代码

    $('#pass').on('click',function(){
        var idArray = [];
        $('.ace.auth_id').each(function(){
            if($(this).is(':checked')){  //判断已选中
                var id = $(this).val();  //判断未选中用if( !this.checked ) { }
                idArray.push(id);
            }
        });
        var ids = idArray.toString();
        console.log(ids);
        $.ajax({
            type: 'post',
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            },
            url: '/manage/allEnterprisePass',
            data: {ids:ids},
            dataType:'json',
            success: function(data){
                if(data.code == 1){
                    $('[type="checkbox"]').prop('checked','');
                    location.reload();
                }
            }
        });
    });

 

posted @ 2019-08-16 14:16  江期玉  阅读(856)  评论(0编辑  收藏  举报