表格背景颜色变换

- 中国WEB开发者网络 (http://www.webasp.net)
-- 网页特效 (http://www.webasp.net/javascript/)
--- 表格背景颜色变换 (http://www.webasp.net/javascript/1/228.htm)
-- 发布日期: 2004-06-18
<!-- 网页特效代码由[中国WEB开发者网络:http://www.ChinaWebDev.com]提供! -->
<!-- 要实现此效果需要 2 个步骤: -->

<!-- 第 1 步: -->
<!-- 把下面的代码加到<HEAD></HEAD>区域中: -->

<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>




<!-- 第 2 步: -->
<!-- 把下面的代码加到<BODY></BODY>区域中: -->

<table width="30%" border="1" align="center" onMouseover="changeto('33ff33')" onMouseout="changeback('black')">
<tr>
<td>
<div align="center">中国WEB开发者网络</div>
</td>
</tr>
<tr>
<td>
<div align="center">中国WEB开发者网络</div>
</td>
</tr>
<tr>
<td>
<div align="center">中国WEB开发者网络</div>
</td>
</tr>
<tr>
<td>
<div align="center">中国WEB开发者网络</div>
</td>
</tr>
<tr>
<td>
<div align="center">中国WEB开发者网络</div>
</td>
</tr>
</table>

webasp.net