Andy Zhao's Blog

  • 首页
  • web开发
  • 互联网
  • 技术分享
  • 网站运营
  • 交互设计
  • 资源分享
    • 工具
    • 欣赏
    • 素材
  • 生活杂语
Welcome
记录一些点点滴滴
  1. 首页
  2. web开发
  3. javascript
  4. 正文

表格隔行变色,鼠标经过变色,兼容IE FF chrome

2013/02/28 1804点热度 0人点赞 0条评论

废话不多说,直接上代码,可查看demo

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>mytable</title>
<script language="JavaScript">
function anole(
str_tableid, // table id
num_header_offset,// 表头行数
str_odd_color, // 奇数行的颜色
str_even_color,// 偶数行的颜色
str_mover_color, // 鼠标经过行的颜色
str_onclick_color // 选中行的颜色
) {

// 表格ID参数验证
if(!str_tableid) return alert(str_tableid+"表格不存在");
var obj_tables=(document.all ? document.all[str_tableid]:document.getElementById(str_tableid));
if(!obj_tables) return alert("ID为("+str_tableid+")不存在!");

// 设置个参数的缺省值
var col_config=[];
col_config.header_offset=(num_header_offset?num_header_offset:0 );
col_config.odd_color=(str_odd_color?str_odd_color:'#ffffff');
col_config.even_color=(str_even_color?str_even_color:'#dbeaf5');
col_config.mover_color=(str_mover_color?str_mover_color:'#6699cc');
col_config.onclick_color=(str_onclick_color?str_onclick_color:'#4C7DAB');
// 初始化表格(可能多个表格用同一个ID)
if(obj_tables.length)
for(var i=0;i<obj_tables.length;i++ )
tt_init_table(obj_tables[i],col_config);
else
tt_init_table(obj_tables,col_config);
}

function tt_init_table(obj_table,col_config) {
var col_lconfig=[],
col_trs=obj_table.rows;
if(!col_trs) return ;

for(var i=col_config.header_offset;i<col_trs.length;i++) { // i 从 表头以下开始
col_trs[i].config=col_config;
col_trs[i].lconfig=col_lconfig;
col_trs[i].set_color=tt_set_color;
col_trs[i].onmouseover=tt_mover;
col_trs[i].onmouseout=tt_mout;
col_trs[i].onmousedown=tt_onclick;
col_trs[i].order=(i-col_config.header_offset)%2 ;
col_trs[i].onmouseout();
}
}
function tt_set_color(str_color) {
this.style.backgroundColor=str_color;
}

// 事件操作
function tt_mover() {
if(this.lconfig.clicked!=this )
this.set_color(this.config.mover_color);
}
function tt_mout() {
if(this.lconfig.clicked!=this )
this.set_color(this.order?this.config.odd_color:this.config.even_color);
}
function tt_onclick() {
if( this.lconfig.clicked==this) {
this.lconfig.clicked=null;
this.onmouseover();
}
else {
var last_clicked=this.lconfig.clicked;
this.lconfig.clicked=this ;
if(last_clicked) last_clicked.onmouseout();
this.set_color(this.config.onclick_color);
}
}

</script>
</head>
<body>
<table bgcolor="#ccc" align="center" cellpadding="1" cellspacing="0" width="80%">
<tr>
<td>
<table id="demo" cellpadding="1" cellspacing="1" border="0" width="100%" align="center">
<tr><th colspan="2" bgcolor="ffffff">HTML document object properties</th></tr>
<tr><td width="20%">activeElement</td><td>Retrieves the object that has the focus.</td></tr>
<tr><td>aLinkColor</td><td>Sets or retrieves the color of all links in the document.</td></tr>
<tr><td>bgColor</td><td>Sets or retrieves the background color behe document object.</td></tr>
<tr><td>body</td><td>Specifies the beginning and end of the document body.</td></tr>
<tr><td>contentEditable</td><td>Sets or retrieves whether the userdocument object.</td></tr>
<tr><td>cookie</td><td>Sets or retrieves the string value of a cookie.</td></tr>
<tr><td>defaultCharset</td><td>Sets or retrieves the default chara of the document.</td></tr>
<tr><td>designMode</td><td>Sets or retrieves whether the document can be edited.</td></tr>
<tr><td>documentElement</td><td>Retrieves a reference to the root node of the document.</td></tr>
<tr><td>domain</td><td>Sets or retrieves the security domain of the document.</td></tr>
</table>
</td>
</tr>
</table>
<script language="JavaScript">
anole('demo',1,'#fafafa','#eee','#fff','#fff');
</script>
</body>
</html>

标签: css html js 表格
最后更新:2013/02/28

zhaoan

一个不起眼的IT工作者,从事过的行业较多,医疗保健、医院、月子会所、机电、重卡、软件,涉及的岗位也较多,零售、市场、平面设计、网站设计、UI设计、前端开发、后端开发、网络布线、设备维护、服务器维护、网络推广、网站运营、新媒体运营、部门管理等等,每个岗位工作基本都能独立完成,但是涉及面广导致都不精通,学习还在继续中。。。

点赞
< 上一篇
下一篇 >

文章评论

取消回复

搜索
分类
  • asp / 2篇
  • css / 27篇
  • html / 9篇
  • javascript / 15篇
  • php / 6篇
  • web开发 / 8篇
  • wordpress / 7篇
  • 互联网 / 16篇
  • 交互设计 / 30篇
  • 其他 / 3篇
  • 工具 / 3篇
  • 欣赏 / 11篇
  • 生活杂语 / 6篇
  • 用户体验 / 1篇
  • 素材 / 3篇
  • 网站建设 / 3篇
  • 网站推广 / 4篇
  • 网站运营 / 5篇
  • 网络技术 / 1篇
最新 热点 随机
最新 热点 随机
宝塔的FTP存储空间,API资料校验失败,请核实! 移动端APP下拉刷新与轮播图冲突的解决方法 头条号怎么运营?怎么涨粉? 转载:移动前端开发之viewport的深入理解 判断来访是搜索引擎蜘蛛还是普通用户,蜘蛛正常抓取,用户跳转指定页面 为什么我们需要构图?构图有哪些原则?
CSS书写规范及顺序 国内网站数据统计选Google Analytics还是百度统计 window.location.href和window.location.replace的区别 前端路上的旅行 成为优秀PHP开发人员做到的5件事 浅析WEB表单设计

COPYRIGHT © 2022 zhaoan.org. ALL RIGHTS RESERVED.

THEME KRATOS MADE BY VTROIS

陕ICP备09022954号