下面是logic:iterate的具体内容,kensakuBeans为传过来的一个链表,如何实现让显示出来的数据隔行的颜色不一样,比如说第一行无背景色,第二行红色,第三行我背景色,第四行又是红色......
<logic:iterate id="kensaku" name="kensakuBeans">
     <tr>
     <td class="settle1"><bean:write name="kensaku" property="tesokuNO"/></td>
<td class="settle1" width="600"><bean:write name="kensaku" property="tesokuName"/></td>
<td align="center" class="settle1" colspan="3"><a href="detail.do?tesokuNO=<bean:write name="kensaku" property="tesokuNO"/>">一覧</a>    </td>     </tr>
     </logic:iterate> 

解决方案 »

  1.   

     <logic:iterate id="list" name="list" indexId="index">
         <tr bgcolor="<%=(index.intValue() % 2 == 0) ? "red" : "blue"%>">
          <td>
           aaaaaaaaaa
          </td>
        </tr>
       </logic:iterate>
      

  2.   

    隔行变色效果
     <%int iRow = 0;%><!--初始化变量-->
     <logic:iterate id="history" name="historylist">
     <%iRow++; %><!--循环递增-->
      <tr <%if(iRow%2==0){%> id="change" <%}%>><!--偶数行改变tr样式--> 
      

  3.   

    建议学struts2,直接用struts2标签如果是奇数行<s:if test="#st.odd">style="background-color:#dddddd"</s:if>
      

  4.   

    <style type="text/css">
    #main  tr {
    background-color:expression((this.sectionRowIndex%2==0)?"#E1F1F1":"#F0F0F0")
    }
    </style>
    <body>
    <table class="main"><logic:iterate id="kensaku" name="kensakuBeans"> 
        <tr> 
        <td class="settle1"> <bean:write name="kensaku" property="tesokuNO"/> </td> 
    <td class="settle1" width="600"> <bean:write name="kensaku" property="tesokuName"/> </td> 
    <td align="center" class="settle1" colspan="3"> <a href="detail.do?tesokuNO= <bean:write name="kensaku" property="tesokuNO"/>">一覧 </a>   </td>     </tr> 
        
        </logic:iterate> 
    </table>
    </body>
      

  5.   

    我倒
    用css不可以么,为什么要浪费性能在这中上面
    如果有100W条数据,就为了这么点小事,就要浪费多少cpu啊~~~~
      

  6.   

    <style type="text/css"> 
    .main { 
    color:expression((this.sectionRowIndex%2==0)?"red":"green") 

    </style> 
    <body> 
    <table > 
    <logic:iterate id="kensaku" name="kensakuBeans"> 
        <tr class="main"> 
        <td class="settle1"> <bean:write name="kensaku" property="tesokuNO"/> </td> 
        <td class="settle1" width="600"> <bean:write name="kensaku" property="tesokuName"/> </td> 
        <td align="center" class="settle1" colspan="3"> <a href="detail.do?tesokuNO= <bean:write name="kensaku" property="tesokuNO"/>">一覧 </a>   </td>     </tr> 
        </logic:iterate> 
    </table> 
    </body> 
      

  7.   

    呵呵一个CSS搞定他!楼上有人顶出来了!collect it!
      

  8.   

    想法很好,但是如果遇到禁用javascript得浏览器怎么办?
      

  9.   

    <logic:iterate id="kensaku" name="kensakuBeans"> 
     
        <tr bgcolor=" <%=(index.intValue() % 2 == 0) ? "red" : "blue"%>"> 
        <td class="settle1"> <bean:write name="kensaku" property="tesokuNO"/> </td> 
    <td class="settle1" width="600"> <bean:write name="kensaku" property="tesokuName"/> </td> 
    <td align="center" class="settle1" colspan="3"> <a href="detail.do?tesokuNO= <bean:write name="kensaku" property="tesokuNO"/>">一覧 </a>   </td>     </tr> 
     
        </logic:iterate>
      

  10.   

    首先判断(用%2得到的是1、还是0)
    然后可以用标签
    <logic:iterate id="kensaku" name="kensakuBeans">
    <logic:equal name="kensaku" property="rowColor" value="1"><tr bgcolor="#FF0000"></logic:equal>
    <logic:equal name="kensaku" property="rowColor" value="0"><tr bgcolor="#FFFFFF"></logic:equal>
    .
    .
    .
    .</logic:iterate> 
      

  11.   

    利用odd 和even奇偶行,有这两个属性
      

  12.   


    <logic:iterate id="list" name="list" indexId="index">
    <c:if test="${index%2 ==0}"
        <tr bgcolor="red">
          <td>
          aaaaaaaaaa
          </td>
        </tr>
    </c:if>
    <c:if test="${index%2 !=0}"
        <tr bgcolor=" green">
          <td>
          bbbbbbbbbb
          </td>
        </tr>
    </c:if>
      </logic:iterate>