您的位置:首页 > 其它

鼠标经过时,改变表格背景颜色

2012-08-20 10:39 543 查看
这是一个当鼠标经过时,改变表格背景颜色的简单示例:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>鼠标经过时,改变表格背景颜色</title>
</head>
<body>
<table width="500" border="1" cellpadding="0" cellspacing="0" id="t">
<tr bgcolor='blue'><td width="500" height="20">1</td></tr>
<tr bgcolor='green'><td width="500" height="20">2</td></tr>
<tr bgcolor='red'><td width="500" height="20">3</td></tr>
<tr bgcolor='#ff9933'><td width="500" height="20">4</td></tr>
<tr bgcolor='#993399'><td width="500" height="20">5</td></tr>
</table>
<script>
;(function(table){
function unit(e){
e = e || event;
return e.target || e.srcElement;
}
var temp = "";
table.onmouseover = function(e){var o=unit(e);temp = this.style.backgroundColor;o.style.backgroundColor = '#ccc';};
table.onmouseout = function(e){var o = unit(e);o.style.backgroundColor = temp};
}(document.getElementById('t')));
</script>
</body>
</html>
希望对大家有所帮助!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: