日期:2014-05-17 浏览次数:20412 次
$style = array(0=>"red",1=>"yellow",2=>"gree");
根据数据库的值 输出样式
$ar1=array(0,1,2);
$ar2=array(0,1,2);
$ar3=array(0,1,2);
$ar4=array(0,1,2);
$ar5=array(0,1,2);
$ar6=array(0,1,2);
$ar7=array(0,1,2);
<table border="1" cellspacing="0" cellpadding="0" width="600">
for($i=0;$i<count($ar1);$i++){
echo "<tr>";
echo "<td>".$ar1[$i]."</td>";
echo "<td>".$ar2[$i]."</td>";
echo "</tr>";
}
</table>
<style type="text/css">
.r{
background-color:red;
}
.y{
background-color:yellow;
}
.g{
background-color:green;
}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$(function(){
$("#abv").click(function(){
$("tr td").each(function(){
if($(this).text()==0){
$(this).addClass("r");
}else if($(this).text()==1){
$(this).addClass("y");
}else{
$(this).addClass("g");
}
});
});
})
</script>
<input type="button" id="abv" value="测试用按钮"/>
<table border="1" cellspacing="0" cellpadding="0" width="600">
<tr>
<td/>0</td>
<td>2</td>
<td>2</td>
<td>1</td>
<td>2</td>
<td>2</td>
<td>1</td>
</tr>
<tr>
<td>2</td>
<td>2</td>
<td>1</td>
<td/>1</td>
<td>1</td>
<td>2</td>
<td>0</td>
</tr>
<tr>
<td/>0</td>
<td>1</td>
<td>2</td>
<td/>0</td>
<td>1</td>
<td>2</td>
<td>0</td>
</tr>
</table>
<style type="text/css">
.col_0 {
background-color:red;
}
.col_1 {
background-color:yellow;
}
.col_2 {
background-color:green;
}
</style>
while($row=mysql_fetch_array($result))
{
echo '<tr>';
for($i=0; $i<7; $i++) {
echo "<td class='col_{$row[$i]}'>{$row[$i]}</td>";
}
echo '</tr>';
}