0

我正在尝试循环颜色,但我没有得到正确的代码。它会变成最后一种颜色。不知道我做错了什么,我一定是错过了一条线或什么的。

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];

  }
 }

谁能帮我找出不同颜色背景的循环?

4

1 回答 1

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++;
     }
 }

工作示例 http://jsfiddle.net/LMdXn/

于 2013-05-07T00:53:40.953 回答