好久没有做网页了,今天接到一个单子,有个功能是实现表格隔行换色,点击后显示其他的颜色,然后得到以下的代码:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>表格table隔行换色以及点击整行变色</title>
<style type="text/css">
.warp_table {border-collapse:collapse; width:550px; border:1px solid #4d9ab0}
.warp_table td {border:1px solid #4d9ab0}
</style>
<script language="javascript"><!--
function senfe(o,a,b,c,d){
var t=document.getElementById(o).getElementsByTagName("tr");
for(var i=0;i<t.length;i++){
t[i].style.backgroundColor=(t[i].sectionRowIndex%2==0)?a:b;
t[i].onclick=function(){
if(this.x!="1"){
this.x="1";
this.style.backgroundColor=d;
}else{
this.x="0";
this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
}
}
t[i].onmouseover=function(){
if(this.x!="1")this.style.backgroundColor=c;
}
t[i].onmouseout=function(){
if(this.x!="1")this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;
}
}
}
--></script>
</head>
<body>
<h1>表格table隔行换色以及点击整行变色</h1>
<h3><a href="http://www.logtu.com" style="color:#000;">www.logtu.com</a></h3>
<table id="changecolor">
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
</table>
<script language="javascript"><!--
//senfe("表格名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景");
senfe("changecolor","#f8fbfc","#e5f1f4","#ecfbd4","#bce774");
--></script>
</body>
</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">? ? <html xmlns="http://www.w3.org/1999/xhtml">? ? <head>? ? <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />? ? <title>表格table隔行换色以及点击整行变色</title>? ? <style type="text/css">? ? .warp_table {border-collapse:collapse; width:550px; border:1px solid #4d9ab0}? ? .warp_table td {border:1px solid #4d9ab0}? ? </style>? ? <script language="javascript"><!--? ? function senfe(o,a,b,c,d){? ? var t=document.getElementById(o).getElementsByTagName("tr");? ? for(var i=0;i<t.length;i++){? ? t[i].style.backgroundColor=(t[i].sectionRowIndex%2==0)?a:b;? ? t[i].onclick=function(){? ? if(this.x!="1"){? ? this.x="1";? ? this.style.backgroundColor=d;? ? }else{? ? this.x="0";? ? this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;? ? }? ? }? ? t[i].onmouseover=function(){? ? if(this.x!="1")this.style.backgroundColor=c;? ? }? ? t[i].onmouseout=function(){? ? if(this.x!="1")this.style.backgroundColor=(this.sectionRowIndex%2==0)?a:b;? ? }? ? }? ? }? ? --></script>? ? </head>? ? <body>? ? <h1>表格table隔行换色以及点击整行变色</h1> ? ?<table id="changecolor">? ? <tr>? ? <td>&nbsp;</td>? ? <td>&nbsp;</td>? ? <td>&nbsp;</td>? ? </tr>? ? <tr>? ? <td>&nbsp;</td>? ? <td>&nbsp;</td>? ? <td>&nbsp;</td>? ? </tr>? ? <tr>? ? <td>&nbsp;</td>? ? <td>&nbsp;</td>? ? <td>&nbsp;</td>? ? </tr>? ? <tr>? ? <td>&nbsp;</td>? ? <td>&nbsp;</td>? ? <td>&nbsp;</td>? ? </tr>? ? <tr>? ? <td>&nbsp;</td>? ? <td>&nbsp;</td>? ? <td>&nbsp;</td>? ? </tr>? ? <tr>? ? <td>&nbsp;</td>? ? <td>&nbsp;</td>? ? <td>&nbsp;</td>? ? </tr>? ? </table>? ? <script language="javascript"><!--? ? //senfe("表格名称","奇数行背景","偶数行背景","鼠标经过背景","点击后背景");? ? senfe("changecolor","#f8fbfc","#e5f1f4","#ecfbd4","#bce774");? ? --></script>? ? </body>? ? </html><code lang="html">

</code>