php怎么实现表格两种颜色
- 建站笔记
- 2022-05-09
- 654
php实现表格两种颜色的方法:1、创建一个table表格;2、通过PHP代码“$i =0;while($i<20){if($i%2==0){$bgcolor = 'BBBBBB';}else{$bgcolor...;}”实现隔行变颜色即可。
本文操作环境:Windows7系统、PHP7.1版、DELL G3电脑
php怎么实现表格两种颜色?
【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>
效果图:
本文由白琉璃于2022-05-09发表在白琉璃源码网,如有侵权或疑问,请联系我们,谢谢。
本文链接:https://www.bailiuli.com/t/3097.html
发表评论