JSP页面的配置:
1 <%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3 <%@ taglib uri="/struts-tags" prefix="s" %> 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 5 <html> 6 <head> 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 8 <title>Insert title here</title> 9 <style type="text/css"> 10 .odd{ 11 background-color: skyblue; 12 } 13 .even{ 14 background-color: pink; 15 } 16 </style> 17 </head> 18 <body> 19 <table border="1px" align="center"> 20 <tr> 21 <th>编号</th> 22 <th>姓名</th> 23 <th>密码</th> 24 <th>年龄</th> 25 <th>货费</th> 26 </tr> 27 28 <s:iterator var="stu" value="#key" status="su"> 29 <!-- 注意:第一个even是个关键字 --> 30 <tr class="<s:property value="#su.even?‘even‘:‘odd‘"/>"> 31 <td> 32 <s:property value="id"/> 33 </td> 34 <td> 35 <s:property value="name"/> 36 </td> 37 <td> 38 <s:property value="password"/> 39 </td> 40 <td> 41 <s:property value="age"/> 42 </td> 43 <td> 44 <s:property value="fees"/> 45 </td> 46 </tr> 47 </s:iterator> 48 </table> 49 </body> 50 </html>
效果:
这样就搞出来简单的表格隔行变色的功能;
时间: 2024-08-02 02:48:54