简体   繁体   English

如何在js中重新启动foreach循环;

[英]how to restart a foreach loop in js;

$('.thumb').each(function(i){ 
                if(i>= 4){
                    $(this).addClass('col-' + (i));
                }{
            $(this).addClass('col-' + (i));

                }

and i want result like我想要这样的结果在此处输入图片说明

what i do to add this class我如何添加这个类

Use the modulo operator:使用模运算符:

$('.thumb').each(function(i){ 
  $(this).addClass('cold-' + (i % 4));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM