鼠标经过时,改变表格背景颜色
来源:互联网 发布:android 录屏软件 编辑:程序博客网 时间:2024/04/30 10:42
这是一个当鼠标经过时,改变表格背景颜色的简单示例:
<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>
希望对大家有所帮助!