我以下樣式:爲HTML元素實現鼠標懸停背景顏色更改的最簡單方法是什麼?
a.button {
background-color: orange;
margin: .2cm;
padding: .2cm;
color: black;
font-family: sans-serif;
text-decoration: none;
font-weight: bold;
border: solid #000000;
}
a.buttonMouseover {
background-color: darkGoldenRod;
margin: .2cm;
padding: .2cm;
color: black;
font-family: sans-serif;
text-decoration: none;
font-weight: bold;
border: solid #000000;
}
而下面的JavaScript代碼(我第一次BTW):
function backgroundChangeIn(element){
if (element.className = "a.button"){element.className = "buttonMouseover";}
}
function backgroundChangeOut(element){
if (element.className = "a.buttonMouseover"){element.className = "button";}
}
而且,這應該改變鼠標懸停在後臺以下元素:
<a class="button" href="" onmouseover="backgroundChangeIn(this)" onmouseout="backgroundChangeOut(this)">A Button</a>
它到目前爲止我工作。但我想知道是否有更好的方法。
(對不起所有的代碼)
感謝拼寫檢查 – jjnguy 2008-11-03 19:53:48