以前没有用SMARTY的时候要实现表格颜色的交替显示,会用jquery来做,但现在的话用了SMARTY,要实现这个样式就很简单了,SMARTY提供了一个函数:cycle.以下是实例代码:
最后实现的效果如下:
http://www.gaodaima.com/49135.htmlSmarty来实现表格颜色交替显示_php
test.php>>>
<?php
include_once("smarty_inc.php");
$arr=array(“a”,”b”,”c”,”d”,”e”,”f”);
$smarty->assign(“arr”,$arr);
$smarty->display("test.tpl");
?>
test.tpl>>>
<table width="100px">
{section name=a loop=$arr}
<tr bgcolor="{cycle values="#eeeeee,#55eero"}">
<td>
{$arr[a]}
</td>
</tr>
{/section}
</table>
以上就代码,使用起来很方便.
欢迎大家阅读《Smarty来实现表格颜色交替显示_php》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码