中 varStatus的作用" type="hidden"/>

中 varStatus的作用


varStatus是<c:forEach>jstl循环标签的一个属性,varStatus属性。

varStatus=“status”事实上定义了一个status名的对象作为varStatus的绑定值。

该绑定值也就是status封装了当前遍历的状态,比如,可以从该对象上查看是遍历到了第几个元素:${status.count}

 

<span style="color: red; font-size: 20px;">${status.count}</span> 写在 c:forEach 里面.

常见的用法的是<c:forEach var="e" items="${ss.list}" varStatus="status">
                                 <!--实现隔行变色效果--> 
                                 <c:if test="${status.count%2==0}" >
                                       <tr  style="color: red; font-size: 20px;"/>
                                  </c:if>

                                  <c:if test="${status.count%2!=0}" >
                                       <tr  style="color: blue; font-size: 20px;"/>
                                  </c:if> 

                        </c:forEach>

     <c:forEach items="${students}" var="s" varStatus="vs">    
         <tr style='background-color: ${vs.count %2==0 ?"blue":"gray"};'>
             <td>${s.id }</td>
             <td>${s.name }</td>
             <td>${s.age }</td>
         </tr>
    </c:forEach>

分行显示蓝色或则灰色。

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM