table隔行换色点击整行变色

/ 7评 / 0

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

<!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>

7条回应:“table隔行换色点击整行变色”

  1. 笑笑博客说道:

    大家試試是什麼樣了,嘻嘻~

  2. 落英纷淘说道:

    我也有个博客,不过好久没有更新了!

  3. Demon说道:

    亲。新年快乐。

  4. 地球博客说道:

    祝博主龙年快乐!

  5. 博主龙年大吉,经常更新呀~~~

  6. 爱蝌蚪说道:

    代码排版好乱。。。

发表评论

电子邮件地址不会被公开。 必填项已用*标注