Equation to change every other two rows
What we want to do is change the background color of row in a table. The color will change for every other two rows.
Our id sequence is simple as follow:
id = 1,2,3,4,5,6,7,8,9,10,11,12,13,14,.....etc.
1,2 rows -> black
3,4 rows -> white
5,6 rows -> black
7,8 rows -> white
9,10 rows -> black
11,12 rows -> white
13,14 rows -> black
15,16 rows -> white
17,18 rows -> black
etc....
if(id==1) ||开发者_StackOverflow中文版 (id==2) class="black";
if(id==3) || (id==4) class="white";
if(id==5) || (id==6) class="black";
if(id==7) || (id==8) class="white";
if(id==9) || (id==10) class="black";
if(id==11) || (id==12) class="white";
etc.....
Depending on that id value, how can we change the color black or white?
Thanks a lot.
bool white = ((rowId - 1) & 2) == 2;
bool white = ((rowId - 1) % 4) >= 2;
switch (id % 4) {
case 1:
case 2:
class="black";
break;
case 3:
case 0:
class="white";
break;
}
bool white = ((rowId + 1) % 4) / 2 == 0
精彩评论