2012-08-02 81 views
1

讀我寫了一個簡單的asp命令從數據庫中檢索HTML顏色代碼,並且這些被顯示在表中作爲如此 -顯示顏色從數據庫

<table border="1" width="75%" cellspacing="0" cellpadding="0" align="right"> 
<tr> 
<%for each x in rs.Fields 
response.write("<th>" & x.name & "</th>") 
next%> 
</tr> 
<%do until rs.EOF%> 
<tr> 
<%for each x in rs.Fields%> 
    <td><%Response.Write(x.value)%></td> 
<%next 
rs.MoveNext%> 
</tr> 
<%loop 
rs.close 
conn.close 
end if 
%> 
</table> 

是否有辦法在包含這些單獨的HTML顏色值的列中,要將其特定單元格的背景設置爲它們各自的顏色?

回答

1

試着寫你的價值作爲背景色

<table border="1" width="75%" cellspacing="0" cellpadding="0" align="right"> 
<tr> 
<%for each x in rs.Fields 
response.write("<th>" & x.name & "</th>") 
next%> 
</tr> 
<%do until rs.EOF%> 
<tr> 
<%for each x in rs.Fields%> 
    <td style="background-color: #<%Response.Write(x.value)%>;"><%Response.Write(x.value)%></td> 
<%next 
rs.MoveNext%> 
</tr> 
<%loop 
rs.close 
conn.close 
end if 
%> 
</table>