【PHP】简单的隔行颜色区分表格的实现

<html>
	<head>
		<title>Creating tables</title>
		<meta charset="utf-8" />
	</head>
	<body>
		<table border="1" style = 'border-collapse: collapse;'align="center">
			<caption><h1>表格示意图</h1></caption>
			<tr>
				<th>学号</th>
				<th>年级</th>
				<th>姓名</th>
				<th>性别</th>
				<th>政治面貌</th>
				<th>年龄</th>
				<th>成绩</th>
				<th>等级</th>
				<th>奖学金</th>
				<th>有无违纪</th>
			</tr>
				<?php
					$i =0;
					while($i<20){					//第一层循环,将第一行循环20
						if($i%2==0){//对数据行进行判断,当为偶数行时,灰色赋给$bgcolor
							$bgcolor = 'BBBBBB';
						}else{
							$bgcolor = 'FFFFFF';
						}
						
						$i++;        
						echo "<tr>";
						$j=0;
						while ($j<10){				//第二层循环,得到10个数据
							$j++;
							echo "<td style = 'text-align :center' bgcolor = $bgcolor>数据</td>";
						}	
						echo "</tr>";
					}
				?>
		</table>
	</body>
</html>

效果图:

猜你喜欢

转载自blog.csdn.net/qq_35621436/article/details/83551973