木子屋 Dnawo's BLOG

CSS控制表格的交替颜色三例

👤 dnawo 📅 2007-12-21 👁 5362 👍 0 💬 0 🔄 51js.com
<style type="text/css">
 <!--
 tr {background-color:expression((this.sectionRowIndex%2==0)?"red":"blue")}
 -->
 </style>
 </HEAD>
 <table>
 <tr><td>第1行</td><td>第1行</td></tr>
 <tr><td>第2行</td><td>第2行</td></tr>
 <tr><td>第3行</td><td>第3行</td></tr>
 <tr><td>第4行</td><td>第4行</td></tr>
 <tr><td>第5行</td><td>第5行</td></tr>
 </table>
 //myhyli @ blueidea
 

 <style type="text/css">
 <!--
 tr {background-color:expression((this.sectionRowIndex%2==0)?"red":"blue")}
 td {background-color:expression((this.cellIndex%2==0)?"":((this.parentElement.sectionRowIndex%2==0)?"green":"yellow"))}
 -->
 </style>
 </HEAD>
 <table>
 <tr><td>第1行</td><td>第1行</td><td>第1行</td><td>第1行</td><td>第1行</td></tr>
 <tr><td>第2行</td><td>第2行</td><td>第2行</td><td>第2行</td><td>第2行</td></tr>
 <tr><td>第3行</td><td>第3行</td><td>第3行</td><td>第3行</td><td>第3行</td></tr>
 <tr><td>第4行</td><td>第4行</td><td>第4行</td><td>第4行</td><td>第4行</td></tr>
 <tr><td>第5行</td><td>第5行</td><td>第5行</td><td>第5行</td><td>第5行</td></tr>
 </table>
 //myhyli @ blueidea
 

<style>
tr{background-color:expression((this.rowIndex%2==0)?"blue":"red");ryo:expression(onmouseover=function(){this.style.backgroundColor=(this.style.backgroundColor!='gray'?'gray':((this.rowIndex%2==0)?"blue":"red"))},onmouseout=function(){this.style.backgroundColor=(this.style.backgroundColor!='gray'?'gray':((this.rowIndex%2==0)?"blue":"red"))})}
</style>
<TABLE width="200" cellpadding="0" cellspacing="2" border="0" id="t1">
<TR>
<TD>111</TD>
</TR>
<TR>
<TD>222</TD>
</TR>
<TR>
<TD>333</TD>
</TR>
<TR>
<TD>444</TD>
</TR>
<TR>
<TD>555</TD>
</TR>
<TR>
<TD>666</TD>
</TR>
<TR>
<TD>777</TD>
</TR>
<TR>
<TD>888</TD>
</TR>
</TABLE>

评论(0)

暂无评论。

计算题
评论需审核通过后显示
← 上一篇 根据判断浏览器类型屏幕分辨率自动调用不同CSS的代码 下一篇 → 一行代码杜绝iframe挂马