Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.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_Html_Checkbox - Fatal编程技术网

Javascript jquery从子元素迭代内部子元素

Javascript jquery从子元素迭代内部子元素,javascript,jquery,html,checkbox,Javascript,Jquery,Html,Checkbox,我有下一个html: <div id="segmenter"> <div id="variable" name="Zone"> <h3>Zona</h3> <ul> <li><input id="category" type="checkbox" value="Center">Center</li> <li&

我有下一个html:

<div id="segmenter">
    <div id="variable" name="Zone">
        <h3>Zona</h3>
        <ul>
            <li><input id="category" type="checkbox" value="Center">Center</li>
            <li><input id="category" type="checkbox" value="East">East</li>
            <li><input id="category" type="checkbox" value="South">South</li>
        </ul>
    </div>
    <div id="variable" name="Type of">
        <h3>Tipo de Restaurante</h3>
        <ul>
            <li><input id="category" type="checkbox" value="Freestander">Freestander</li>
            <li><input id="category" type="checkbox" value="Instore">Instore</li>
            <li><input id="category" type="checkbox" value="Mall">Mall</li>
        </ul>
    </div>
</div>
我得到每个div变量:
[​…​​, ​…​​]

现在,从这里开始,我尝试的一切都不起作用,例如:

$("#segmenter > #variable").find("#category");
我只得到4个输入“类别”:
[​, ​, ​, ​]

我不知道为什么,我需要的是迭代如下内容:

var oVariables = $("#segmenter > #variable");
$.each(oVariables, function(){
    var oCategory = $(this).find("#category").text();//in the first call for div-name="zone", only have the first input-value"center"
    //Iterate Again
        //get checked values, etc
});

非常感谢。

id是唯一的。对于集合,请改用类。将所有id更改为类,然后进行如下迭代:

$.each($('div.variable'), function(elem){
    $.each($(elem).find('input.category'), function(childElem){
        //Do something with childElem here
    })
});

id是唯一的。对于集合,请改用类。将所有id更改为类,然后进行迭代:

$.each($('div.variable'), function(elem){
    $.each($(elem).find('input.category'), function(childElem){
        //Do something with childElem here
    })
});

不要使用ID!!!ID是唯一的!!!尝试改用类来代替ID!!!ID是唯一的!!!尝试改用类来代替ID应该总是唯一的

在您的案例中使用类而不是ID。例如:

<div id="variable" name="Zone">
    _^_ here
<div class="variable" name="Zone"> //do this for all ids

ID应始终是唯一的

在您的案例中使用类而不是ID。例如:

<div id="variable" name="Zone">
    _^_ here
<div class="variable" name="Zone"> //do this for all ids

我也有同样的问题。我需要访问新的子标签

我的方式:

var list_group_items = $("a.list-group-item");
    $.each(list_group_items,function(index,value){
        $(list_group_items[index]).hover(function(){
            $.each($(list_group_items[index]).find('small'), function(childElem,Element){
                console.log(Element);
                TweenLite.to(Element, 2, {"visibility":"visible"});
            });

        },function(){
            $.each($(list_group_items[index]).find('small'), function(childElem,Element){
                //Do something with childElem here
                TweenLite.to(Element, 2, {"visibility":""});
            });

        });
    });
注1:on
$。每个
函数都有两个参数,第一个是iterate的索引,第二个是元素


注2:我正在使用TeenMax库制作动画。

我也有同样的问题。我需要访问新的子标记

我的方式:

var list_group_items = $("a.list-group-item");
    $.each(list_group_items,function(index,value){
        $(list_group_items[index]).hover(function(){
            $.each($(list_group_items[index]).find('small'), function(childElem,Element){
                console.log(Element);
                TweenLite.to(Element, 2, {"visibility":"visible"});
            });

        },function(){
            $.each($(list_group_items[index]).find('small'), function(childElem,Element){
                //Do something with childElem here
                TweenLite.to(Element, 2, {"visibility":""});
            });

        });
    });
注1:on
$。每个
函数都有两个参数,第一个是iterate的索引,第二个是元素


注2:我使用TeenMax库制作动画。

id
是唯一的。对于集合,请使用
classes
来代替。当您对它们进行迭代时,您想做什么?抱歉,这部分仍然不清楚。@nickcoxdotme获取所有选中的值并将它们传递给某个控制器的操作,
id
是唯一的。使用
classes
相反,对于集合。当您迭代它们时,您想做什么?抱歉,这部分仍然不清楚。@nickcoxdotme获取所有检查值并将它们传递给某个控制器的操作
childElem
是元素的索引…对于access元素,您必须像
$一样执行操作。每个($(elem).find('input.category'),函数(childElem,Element){//Do thing with childElem here})
childElem
是元素的索引…对于访问元素,您必须像
$一样执行。每个($(elem.find($(input.category)),函数(childElem,Element){//Do thing with childElem here})