我正在尝试循环颜色,但我没有得到正确的代码。这是最后一种颜色。不知道我做错了什么,我必须错过一条线或什么的。
var forum = $('.main-content .statused tr'),i;
var colors = ["#000","#F00","#FF0","#FFF","#0F0","#00F"];
for(var j=0;j<forum.length;j++) {
forumBG= forum[parseInt(j)];
if(!forumBG) return;
for (i=0;i<colors.length; i++){
forum[j].style.background =colors[i];
}
}
任何人都可以帮助我找出不同颜色背景的循环吗?
答案 0 :(得分:1)
var forum = $('.main-content .statused tr'),i;
var colors = ["#000","#F00","#FF0","#FFF","#0F0","#00F"];
var i = 0;
for(var j=0;j<forum.length;j++) {
forumBG= forum[j];
if(!forumBG) return;
forum[j].style.background =colors[i];
if(i == colors.length -1){
i= 0;
}else{
i++;
}
}