丢丢 2006-4-25 13:55
求助!如何实现高亮度?
表格的行,鼠标经过时,变为另一种颜色(如:#f2f2f2),点击此行后,此行的颜色变为另一种(如:#d2e8ff,高亮度的颜色),之后,鼠标再经过这行时,还是变回#f2f2f2,后移走后还是#d2e8ff,不知道明白了没有,还有一点,我的这样的表格不止一个,所以希望写成函数.由于是内部用,ie支持便可.比较紧,大家帮帮忙!
eujf 2006-4-25 13:56
这是你要的效果吗?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>highLight</title>
<style>
td{ font-family: Courier New; font-size: 12px; text-align: center ;height:30;word-break:break-all;}
</style>
</head>
<body>
<script defer>
//***by fason(2003-6-21)****//
var i=0;
var h=[]
function myTestTable(oTb,oBgOver,oBgLight){
h[i]=[null,null,oBgOver,oBgLight]
var t=document.getElementById(oTb);
for(m=0;m<t.rows.length;m++){
t.rows[m].attachEvent("onmouseover",new Function("oOver("+i+")"))
t.rows[m].attachEvent("onmouseout",new Function("oOut("+i+")"))
t.rows[m].attachEvent("onclick",new Function("oLight("+i+")"))
}
i++;
}
function oOver(n){
var e=event.srcElement;
if(e.tagName!="TD")return;
e=e.parentElement
h[n][1]=e.currentStyle.backgroundColor
e.style.backgroundColor=h[n][2]
}
function oOut(n){
var e=event.srcElement;
if(e.tagName!="TD")return;
e=e.parentElement
e.style.backgroundColor=h[n][1]
}
function oLight(n){
var e=event.srcElement;
if(e.tagName!="TD")return;
e=e.parentElement
if(h[n][0]==null)h[n][0]=e;
h[n][0].style.backgroundColor=h[n][1]
h[n][0].style.color=''
h[n][0]=e;
h[n][1]=e.style.backgroundColor=h[n][3]
}
myTestTable("test","#f2f2f2","#d2e8ff")
myTestTable("myTable","#d2e8ff","#f2f2f2")
</script>
<table id='myTable' border="1" width=100>
<tr>
<td width="100%">td1</td>
</tr>
<tr>
<td width="100%">td2</td>
</tr>
<tr>
<td width="100%">td3</td>
</tr>
<tr>
<td width="100%">td4</td>
</tr>
</table>
<table border="1" width="100" id='test'>
<tr>
<td width="100%">td1</td>
</tr>
<tr>
<td width="100%">td2</td>
</tr>
<tr>
<td width="100%">td3</td>
</tr>
<tr>
<td width="100%">td4</td>
</tr>
</table>
</body>
</html>