表格隔行换色+鼠标经过变色

<!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>简单表格隔行换色+鼠标经过变色</title>
</head>
<body>
<style>
*{border:none;}
table{width:100%;border:1px solid silver;margin-bottom:30px;background:#F7F7F7}
</style>
<table id="tb1">
<tr ><td> </td></tr>
<tr ><td> </td></tr>
<tr ><td> </td></tr>
<tr ><td>点一下我</td></tr>
<tr ><td>点一下我</td></tr>
<tr ><td>点一下我</td></tr>
</table>
<table id="tb2">
<tr ><td> </td></tr>
<tr ><td> </td></tr>
<tr ><td> </td></tr>
<tr ><td> </td></tr>
<tr ><td> </td></tr>
<tr ><td> </td></tr>
</table>
<script>
//代码如下
var G = function(id){return document.getElementById(id)}
var EACH = function(o,fn){for(var i=0;i<o.length;i++){fn.call(o[i],i,o); if(i==o.length-1) return o}}
var _2009_ = function(){this.init.apply(this,arguments)};
_2009_.prototype={
init:function(o){
EACH(G(o.id).rows,function(i,O){
var d=false;
i%2== +!!o.parity ? this.style.background = o.cor1:'';
this['color2'] = this['color'] = this.style.background;
this.onmouseover = function(){this.style.background = o.cor2}
this.onclick = function(){d?(this.style.background = this['color2'] = this['color'],d=false):(this.style.background = this['color2'] = o.cor3,d=true);}
this.onmouseout = function(){this.style.background = this['color2']}
})
}
};
//用法如下.可设定奇偶.
new _2009_({id:'tb1',cor1:'#DDDDE4',cor2:'#BAD0FC',cor3:'#FFFF99'});
new _2009_({id:'tb2',cor1:'#DDDDE4',cor2:'#BAD0FC',cor3:'#FFFF99',parity:'默认是奇数,设了就是偶数'});
</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值