Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.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统计特定div中的div,然后在添加新div时重置count_Javascript_Jquery - Fatal编程技术网

Javascript jQuery统计特定div中的div,然后在添加新div时重置count

Javascript jQuery统计特定div中的div,然后在添加新div时重置count,javascript,jquery,Javascript,Jquery,我正在使用.each来计算另一个div中的div,但是我有多个具有相同类的div,并且我希望每个新div包装从0开始计算 抱歉,这有点难以解释,因此这里有一个指向workin JSFIDLE的链接: 1.)单击“添加季节性价格过滤器” 2.)单击“添加价格规则”,您将看到它显示“价格规则#1”(工作正常) 3.)再次单击“添加价格规则”,您将看到它显示“价格规则#2”(仍正常工作) 4.)再次单击“添加季节性价格过滤器” 5.)在新的季节性价格过滤器中单击“添加价格规则”,您将看到它显示“价格规

我正在使用.each来计算另一个div中的div,但是我有多个具有相同类的div,并且我希望每个新div包装从0开始计算

抱歉,这有点难以解释,因此这里有一个指向workin JSFIDLE的链接:

1.)单击“添加季节性价格过滤器”

2.)单击“添加价格规则”,您将看到它显示“价格规则#1”(工作正常)

3.)再次单击“添加价格规则”,您将看到它显示“价格规则#2”(仍正常工作)

4.)再次单击“添加季节性价格过滤器”

5.)在新的季节性价格过滤器中单击“添加价格规则”,您将看到它显示“价格规则#3”(不起作用,我希望它显示为“价格规则#1”,因为它位于不同的分区中)

以下是计算数字/计数器的函数:

function recacluclate() {

        $( ".price-rule-wrapper-outer").children('div').each(function(index) {
            $(this).find('.price-rule-number span').text(index + 1);
        });

        $( ".seasonal-filter-wrapper-outer").children('div').each(function(index) {
            $(this).find('.seasonal-filter-number span').text(index + 1);
        });

        $( ".seasonal-filter-wrapper-outer .price-rule-wrapper-outer").children('div').each(function(index) {
            $(this).find('.price-rule-number span').text(index + 1);
        });

        $( ".price-rule-wrapper-outer").children('div').each(function(index) {
            $(this).find('.standard-adult-weekday').attr('name', 'standard-adult-weekday-' + (index + 1));
            $(this).find('.standard-adult-weekend').attr('name', 'standard-adult-weekend-' + (index + 1));
            $(this).find('.standard-child-weekday').attr('name', 'standard-child-weekday-' + (index + 1));
            $(this).find('.standard-child-weekend').attr('name', 'standard-child-weekend-' + (index + 1));
        });

    }
非常感谢任何帮助

更换

$( ".seasonal-filter-wrapper-outer .price-rule-wrapper-outer").children('div').each(function(index) {
    $(this).find('.price-rule-number span').text(index + 1);
});


我认为这是您的问题:
$(“.price rule wrapper outer”).children('div')。每个
-所有
div
子元素。price rule wrapper outer
元素首先组合到一个集合中,然后作为一个整体循环,得到一个连续计数的索引。您实际需要的可能是类似于
$(“.price rule wrapper outer”)。每个(…)
-然后在其中获取特定外部包装的div子级,并为这些子级设置索引。
$(".seasonal-filter-wrapper-outer .price-rule-wrapper-outer").each(function() {
  $(this).children('div').each(function(index) {
    $(this).find('.price-rule-number span').text(index + 1);
  });
})