Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/421.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 如何访问对象';将对象放置在jQuery中的对象中时的子对象_Javascript_Jquery_Arrays - Fatal编程技术网

Javascript 如何访问对象';将对象放置在jQuery中的对象中时的子对象

Javascript 如何访问对象';将对象放置在jQuery中的对象中时的子对象,javascript,jquery,arrays,Javascript,Jquery,Arrays,我将对我正在处理的信息建立一个关联数组。我有以下代码: var controls = {}; $('#userForm').find('div.control').each(function(index, Element) { if($(Element).find('input').attr('type') == "checkbox") { var attributes = {}; // Object attributes["type"] = "c

我将对我正在处理的信息建立一个关联数组。我有以下代码:

var controls = {};
$('#userForm').find('div.control').each(function(index, Element)
{
    if($(Element).find('input').attr('type') == "checkbox")
    {
        var attributes = {}; // Object
        attributes["type"] = "checkbox";
        attributes["name"] = $(Element).find('.controlText').text().toLowerCase().split(" ").join("_")+"_"+$(Element).find('input').attr("id");
        attributes["required"] = $(Element).find('input').hasClass('required');
        controls[index] = attributes;
        $(controls[index]).children().each(function(){
            // How do i check the controls object each value 
            alert($(this));

          });
    }
});
我想制作一个控件数组,在这样的索引中分别包含每个输入的属性

controls [0] => [type] = checkbox [name] = chk_box_1 [required] = true [1] => [type] = checkbox [name] = chk_box_2 [required] = false 控制 [0] => [键入]=复选框 [名称]=chk_箱_1 [必需]=真 [1] => [键入]=复选框 [名称]=chk_box_2 [必需]=错误 ……诸如此类


如何填充控件数组,然后在javascript中查看元素并将它们传递给php并在那里打印数组?

使其成为对象数组

var controls = [];
$('#userForm').find('div.control').each(function (index, elm) {
    if ($(elm).find('input').attr('type') == "checkbox") {
        var attributes = {}; // Object
        attributes["type"] = "checkbox";
        attributes["name"] = $(elm).find('.controlText').text().toLowerCase().split(" ").join("_") + "_" + $(elm).find('input').attr("id");
        attributes["required"] = $(elm).find('input').hasClass('required');
        controls.push(attributes);
    }
});
现在像这样访问它

for(var i = 0; i < controls.length; i++){
    //alert(controls[i].name);
}
for(变量i=0;i