Jquery如何从已选中的复选框中获取数组

Ric*_*aaf 1 arrays ajax jquery

我需要将数据作为数组传递给JQuery中的fancybox实例.

传递的格式需要如下所示: Array( [remove] => Array ( [1] => 1 [109] => 109 [110] => 110 ))

现在我使用以下代码,但这不起作用,因为我没有传递数组.

提前致谢...

复选框看起来像这样,并在数据库结果上生成:

<td class="checkboxTable"><input name="remove[<?php echo $users->id; ?>]" type="checkbox" id="checkbox[]" value="<?php echo $users->id; ?>"/></td>
Run Code Online (Sandbox Code Playgroud)

我使用的javascript是这样的:

$('.deleteConfirmationMultiple').Loader({
    url: ['/dgpcms/public/fancybox/jquery.fancybox-1.3.2.pack.js',
        '/dgpcms/public/fancybox/jquery.easing-1.3.pack.js',
        '/dgpcms/public/fancybox/jquery.mousewheel-3.0.4.pack.js',
        '/dgpcms/public/fancybox/jquery.fancybox-1.3.2.css'],
    ////debug: [true],
    cache: [true],
    success: function(target){
        $(this).fancybox({
            'autoDimensions'    : true,
            'autoScale'         : true,
            'overlayOpacity'    : '0.70',
            'overlayColor'      : '#000000',
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'hideOnOverlayClick': false,
            'hideOnContentClick': false,
            'showCloseButton'   : false,
            'href'              : $('#deleteConfirmation').attr('action'),
            ajax : {
                    type    : 'POST',
                    data    : $('input:checkbox:checked')
                }
        });
    }
}); 
Run Code Online (Sandbox Code Playgroud)

有没有办法像PHP那样完全传递值(如下所示:) Array ( [remove] => Array ( [1] => 1 [109] => 109 [110] => 110 ) [deleteMultiple] => Delete selected )

编辑2011年1月12日

我有点进一步,但是nof有一个奇怪的问题..

我的ajax调用中不会将ID作为数据发布.当我为checkall链接创建一个onclick函数(所有复选框都被选中)并调用getData函数并提醒结果时,我得到了复选框的id.但是在我的ajax调用中调用该函数会返回空...

这是代码:

$('.deleteConfirmationMultiple').Loader({
    url: ['/dgpcms/public/fancybox/jquery.fancybox-1.3.2.pack.js',
        '/dgpcms/public/fancybox/jquery.easing-1.3.pack.js',
        '/dgpcms/public/fancybox/jquery.mousewheel-3.0.4.pack.js',
        '/dgpcms/public/fancybox/jquery.fancybox-1.3.2.css'],
    ////debug: [true],
    cache: [true],
    success: function(target){
        // Array( [remove] => Array ( [1] => 1 [109] => 109 [110] => 110 ))
        // var id = {5: '5', 6: '6', 7: '7'};

        var id = '';
        $.fn.getData = function(options){
            var id = $('input:checkbox:checked').map(function(){
                return this.value.serialize();
            }).get();
            //alert(id);
            return id;
        };

        $(this).fancybox({
            'autoDimensions'    : true,
            'autoScale'         : true,
            'overlayOpacity'    : '0.70',
            'overlayColor'      : '#000000',
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'hideOnOverlayClick': false,
            'hideOnContentClick': false,
            'showCloseButton'   : false,
            'href'              : $('#deleteConfirmation').attr('action'),
            ajax : {
                    type    : 'POST',
                    data    : {'remove':id}
                    }
        });         
    }
}); 
Run Code Online (Sandbox Code Playgroud)

编辑2010年1月12日

下面的代码,包含一个硬编码的数组正是我想要的,现在我需要从选中的复选框创建相同的东西....

var id = {5: '5', 6: '6', 7: '7'};

        $(this).fancybox({
            'autoDimensions'    : true,
            'autoScale'         : true,
            'overlayOpacity'    : '0.70',
            'overlayColor'      : '#000000',
            'transitionIn'      : 'none',
            'transitionOut'     : 'none',
            'hideOnOverlayClick': false,
            'hideOnContentClick': false,
            'showCloseButton'   : false,
            'href'              : $('#deleteConfirmation').attr('action'),
            ajax : {
                    type    : 'POST',
                    data    : {'remove':id}
                    }
        });     
Run Code Online (Sandbox Code Playgroud)

Nic*_*ver 6

我不确定你要传递的确切格式,但要获得一个数组而不是这个:

$('input:checkbox:checked')
Run Code Online (Sandbox Code Playgroud)

...获取一组元素(jQuery对象),用于.map()获取其值的数组,如下所示:

$('input:checkbox:checked').map(function() { return this.value; }).get();
Run Code Online (Sandbox Code Playgroud)