鼠標經過時,改變表格背景顏色

這是一個當鼠標經過時,改變表格背景顏色的簡單示例:
<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>
希望對大家有所幫助!
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章