Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 获取具有选中和未选中状态的所有复选框的列表_Javascript_Php_Jquery_Html - Fatal编程技术网

Javascript 获取具有选中和未选中状态的所有复选框的列表

Javascript 获取具有选中和未选中状态的所有复选框的列表,javascript,php,jquery,html,Javascript,Php,Jquery,Html,我有以下代码,以显示一个图像及其复选框。它是启用或禁用的 if($ring["status"] != '1') echo '<td><input type="checkbox" name="ringIds[]" value="'.$ring["id"].'">' . '<input type="image" on

我有以下代码,以显示一个图像及其复选框。它是启用或禁用的

 if($ring["status"] != '1') 
                                        echo '<td><input type="checkbox" name="ringIds[]" value="'.$ring["id"].'">'
                                    . '<input type="image" onClick="openGalleryRing(\''.$ring['imagePath'].'\', \''.$ring['id'].'\');" src="http://thevowapp.com/iphoneapp/vowstore/rings/'.  $ring['imagePath'] .'" name="checked" value="' . $ring['id'].'" data-my-info="'. $ring['ringSetName'] .'" style="width:200px; height:200px; margin-left: 10px;"></td>';
                                    else                                         
                                         echo '<td><input type="checkbox" checked="checked"  name="ringIds[]" value="'.$ring["id"].'">'
                                    . '<input type="image" onClick="openGalleryRing(\''.$ring['imagePath'].'\', \''.$ring['id'].'\');" src="http://thevowapp.com/iphoneapp/vowstore/rings/'.  $ring['imagePath'] .'" name="checked" value="' . $ring['id'].'" data-my-info="'. $ring['ringSetName'] .'" style="width:200px; height:200px; margin-left: 10px;"></td>';

这是可行的,我可以得到所有选中的复选框,但我真正想要的是得到所有的复选框列表,哪些是选中的,哪些不是。如何修改此代码

以下是您要查找的代码:

$('.updateBtn').on('click', function()
{
    var check_boxes = $('input[name="ringIds[]"]').serialize(); 
    // Try below line to see all checkboxes
    console.log(check_boxes);

}); 

以下是您要查找的代码:

$('.updateBtn').on('click', function()
{
    var check_boxes = $('input[name="ringIds[]"]').serialize(); 
    // Try below line to see all checkboxes
    console.log(check_boxes);

}); 

因此,
.serialize()
将只返回选中的复选框,无论是否包含伪选择器
:选中的

您可能需要使用
.each()
.map()
来获取未选中的复选框

var unchecked = "";
$('input[name="ringIds[]"]').not(':checked').each(function() {
    unchecked += (unchecked.length ? '&' + '') + this.name + '=' + this.value;
});
或:

因此,
.serialize()
将只返回选中的复选框,无论是否包含伪选择器
:选中的

您可能需要使用
.each()
.map()
来获取未选中的复选框

var unchecked = "";
$('input[name="ringIds[]"]').not(':checked').each(function() {
    unchecked += (unchecked.length ? '&' + '') + this.name + '=' + this.value;
});
或:


如果您得到所有选中和未选中的元素,您如何知道哪些是选中的
var checked=$('input[name=“ringIds[]”)。serialize()
如果您获得了所有选中和未选中的元素,您将如何知道哪些元素是选中的
var checked=$('input[name=“ringIds[]”)。serialize()RingID%5B%5D=12&RingID%5B%5D=15&RingID%5B%5D=19这是我得到的,很明显它只显示那些被检查的。即使使用Serialized,我也希望获得已检查和未检查的戒指列表RingID%5B%5D=12&RingID%5B%5D=15&RingID%5B%5D=19这是我得到的,显然它只显示已检查的戒指。即使使用Serialize,我也希望得到已检查和未检查的环列表