jQuery实现表格隔行换颜色:

jQuery实现表格各行换颜色:

截图如下:

jQuery实现表格隔行换颜色:

代码如下:

<span style="font-family:Microsoft YaHei;font-size:14px;"><%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>表格各行变色</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
	$(function(){
		$("tr:odd").addClass("odd");	<%--为基数行添加样式--%>
		$("tr:even").addClass("even");	<%--为偶数行添加样式--%>
	});	
</script>
<style type="text/css">
	.even{
		background: #ffcccc;	<%--定义偶数行样式--%>
	}
	.odd{
		background: #66cccc;	<%--定义基数行样式--%>
	}
</style>
</head>

<body>
<table width="383" height="257" border="1" align="center">
	<tr>
		<td width="121"><div align="center">学号</div></td>
		<td width="171"><div align="center">姓名</div></td>
		<td width="139"><div align="center">专业</div></td>
	</tr>
	<tr>
		<td><div align="center">0101</div></td>
		<td><div align="center">小城</div></td>
		<td><div align="center">小学教育</div></td>
	</tr>
	<tr>
		<td><div align="center">0101</div></td>
		<td><div align="center">小城</div></td>
		<td><div align="center">小学教育</div></td>
	</tr>
	<tr>
		<td><div align="center">0101</div></td>
		<td><div align="center">小城</div></td>
		<td><div align="center">小学教育</div></td>
	</tr>
	<tr>
		<td><div align="center">0101</div></td>
		<td><div align="center">小城</div></td>
		<td><div align="center">小学教育</div></td>
	</tr>
	<tr>
		<td><div align="center">0101</div></td>
		<td><div align="center">小城</div></td>
		<td><div align="center">小学教育</div></td>
	</tr>
	<tr>
		<td><div align="center">0101</div></td>
		<td><div align="center">小城</div></td>
		<td><div align="center">小学教育</div></td>
	</tr>
	<tr>
		<td><div align="center">0101</div></td>
		<td><div align="center">小城</div></td>
		<td><div align="center">小学教育</div></td>
	</tr>
</table>
</body>
</html>
</span>


你可能感兴趣的:(jquery)