六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 157|回复: 0

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

[复制链接]

升级  47%

105

主题

105

主题

105

主题

举人

Rank: 3Rank: 3

积分
341
 楼主| 发表于 2013-2-5 02:12:33 | 显示全部楼层 |阅读模式
要使光标经过表格行时,行的背景颜色发生变化。可以使用:,注意:所在行的单元格不能设置了背景颜色。光标离开时变回原来的背景颜色: 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>
    <td  onmouseout="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%">
  <tr  onMouseout="changeback('white')">
    <td width="100%"> </td>
  </tr>
  <tr  onMouseout="changeback('white')">
    <td width="100%"> </td>
  </tr>
  <tr  onMouseout="changeback('white')">
    <td width="100%"> </td>
  </tr>
</table>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表