光标经过表格行时变背景颜色
要使光标经过表格行时,行的背景颜色发生变化。可以使用:,注意:所在行的单元格不能设置了背景颜色。光标离开时变回原来的背景颜色: onmouseout="this.style=bgColor='#ffffff'"注意 bgColor的"c"应大写,可以利用此方法给单元格加背景颜色。
代码如下:
<table width="600" border="0" cellpadding="5" cellspacing="1" bgcolor="#CCCCCC">
<tr bgcolor="#FFFFFF" onmouseout="this.style=bgColor='#FFFFFF'">
<td width="137"> </td>
<td width="440" > </td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="57"> </td>
<tdonmouseout="this.style=bgColor=''"> </td>
</tr>
</table>
--------------------------------------------------------------------
下面介绍第二种方法,JS调用:
<script language="JavaScript1.2">
function changeto(highlightcolor){
source=event.srcElement
if (source.tagName=="TR"||source.tagName=="TABLE")
return
while(source.tagName!="TD")
source=source.parentElement
if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
source.style.backgroundColor=highlightcolor
}
function changeback(originalcolor){
if (event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")
return
if (event.toElement!=source)
source.style.backgroundColor=originalcolor
}
</script>
<!--以下是你代码是用来触发事件的,也是改变颜色的地方-->
<table border="1" width="54%">
<tronMouseout="changeback('white')">
<td width="100%"> </td>
</tr>
<tronMouseout="changeback('white')">
<td width="100%"> </td>
</tr>
<tronMouseout="changeback('white')">
<td width="100%"> </td>
</tr>
</table>
页:
[1]