table隔行换色点击整行变色

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

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

未经允许不得转载:WEIXING.ME » table隔行换色点击整行变色

相关文章

评论 (0)

  1. avatar

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

  2. avatar

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

    • avatar
      WEIXING01-17 22:58回复

      嗯,我现在更新也不是很勤快了!

  3. avatar
    Demon01-22 20:53回复

    亲。新年快乐。

  4. avatar

    祝博主龙年快乐!

  5. avatar

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

  6. avatar
    爱蝌蚪02-08 15:32回复

    代码排版好乱。。。