Home >Web Front-end >JS Tutorial >Javascript modification table background color example code sharing_javascript skills

Javascript modification table background color example code sharing_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:09:561095browse

Copy code The code is as follows:


<script> <br>//点击当前选中行的时候设置当前行的颜色,同时恢复除当前行外的行的颜色及鼠标事件 <br>function selectRow(target) <br>{ <br>     var sTable = document.getElementById("ServiceListTable") <br>     for(var i=1;i<sTable.rows.length;i++) //遍历除第一行外的所有行 <BR> { <BR> if (sTable.rows[i] != target) //判断是否当前选定行 <BR> { <BR> sTable.rows[i].bgColor = "#ffffff"; //设置背景色 <BR> sTable.rows[i].onmouseover = resumeRowOver; //增加onmouseover 事件 <BR> sTable.rows[i].onmouseout = resumeRowOut;//增加onmouseout 事件 <BR> } <BR> else <BR> { <BR> sTable.rows[i].bgColor = "#d3d3d3"; <BR> sTable.rows[i].onmouseover = ""; //去除鼠标事件 <BR> sTable.rows[i].onmouseout = ""; //去除鼠标事件 <BR> } <BR> } <BR>} <BR>//移过时tr的背景色 <BR>function rowOver(target) <BR>{ <BR> target.bgColor='#e4e4e4'; <BR>} <BR>//移出时tr的背景色 <BR>function rowOut(target) <BR>{ <BR> target.bgColor='#ffffff'; <BR>} <BR>//恢复tr的的onmouseover事件配套调用函数 <BR>function resumeRowOver() <BR>{ <BR> rowOver(this); <BR>} <BR>//恢复tr的的onmouseout事件配套调用函数 <BR>function resumeRowOut() <BR>{ <BR> rowOut(this); <BR>}   <BR></script>

关于最后两个函数resumeRowOver和resumeRowOut为什么这样写参考我之前写的通过js给页面元素添加事件对应的表格HTMLview plaincopy to clipboardprint?

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
服务事项N状态办结资料
相关内容    
相关内容    
相关内容    
相关内容    
 


 
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn