光标经过表格行时变背景颜色

[color=brown]要使光标经过表格行时,行的背景颜色发生变化。可以使用:οnmοuseοver="this.styl=bgColor='#999999'",注意:所在行的单元格不能设置了背景颜色。光标离开时变回原来的背景颜色: οnmοuseοut="this.style=bgColor='#ffffff'"
注意 bgColor的"c"应大写,可以利用此方法给单元格加背景颜色。
代码如下:
<table width="600" border="0" cellpadding="5" cellspacing="1" bgcolor="#CCCCCC">
<tr bgcolor="#FFFFFF" οnmοuseοver="this.style=bgColor='#999999'" οnmοuseοut="this.style=bgColor='#FFFFFF'">
<td width="137"> </td>
<td width="440" > </td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="57"> </td>
<td οnmοuseοver="this.style=bgColor='#CCCCCC'" οnmοuseοut="this.style=bgColor=''"> </td>
</tr>
</table>
[/color]
--------------------------------------------------------------------
下面介绍第二种方法,JS调用:
[color=red]<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%">
<tr onMouseover="changeto('#fff362')" onMouseout="changeback('white')">
<td width="100%"> </td>
</tr>
<tr onMouseover="changeto('#ff5525')" onMouseout="changeback('white')">
<td width="100%"> </td>
</tr>
<tr onMouseover="changeto('#ff2262')" onMouseout="changeback('white')">
<td width="100%"> </td>
</tr>
</table>[/color]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值