2011-12-24 88 views

回答

0

我用rgba顏色一招:

try {elem.style.background = "rgba(255,255,255,0.5)";} 
catch(e) {elem.style.background = "#cccccc";} 

您可以輕鬆地適應這個問題的方法:

try {elem.style.color = "inherit";} // or "currentColor" which is synonymous here 
catch(e) {elem.style.color = "red";} // or whatever fallback you want 

或者,tr Ÿ這個代替:

if(typeof getComputedStyle == "undefined") 
    getComputedStyle = function(elm) {return elm.currentStyle;} 
elem.style.color = getComputedStyle(elem.parentNode).color; 

這將讓父節點,這是基本相同inherit ING的計算樣式(currentStyle中老年IE)。

+0

謝謝。正是我需要的! – Luc 2011-12-27 08:40:41

+0

如果您的問題已被解答,請接受答案。 – 2011-12-27 16:08:29