`
zhulin014
  • 浏览: 51016 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
文章分类
社区版块
存档分类
最新评论

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

阅读更多
<!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>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics