的CSS「懸停」選擇applys臨時風格的元素,它不是明確的:臨時的onmouseover
div:hover {
background-color: red;
}
我可以做的JavaScript同樣的事情,但它是幾個元素有點複雜,也不可能:
var elem = document.getElementsByTagName ("div")[0];
elem.onmouseover = function() {
this.style.backgroundColor = "red";
}
elem.onmouseout = function() {
this.style.backgroundColor = "transparent";
}
有沒有更好的方法?事情是這樣的:
document.getElementsByTagName ("div")[0].ontemporarymouseover = function() { // LoL
this.style.backgroundColor = "red";
}
感謝
在這種情況下,「不確定」是什麼意思? – Quentin 2010-05-16 15:39:58
函數'getElementByTagName'不存在。只有'getElementsByTagName'。這肯定是你有問題的原因。 – 0x2D9A3 2010-05-16 15:45:41
除了我之前的評論,我的直覺告訴你正在嘗試使用JavaScript來解決級聯缺乏理解的問題:http://www.w3.org/TR/CSS21/cascade.html#specificity – Quentin 2010-05-16 15:54:12