有没有办法检查javascript浏览器是否接受css color属性的值'inherit',即object.stye.color='inherit'
是否不会导致错误(在IE 7中确实如此)。
答案 0 :(得分:0)
这可能有助于检测css属性:Css Properties Detection
希望有所帮助
答案 1 :(得分: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
或者,试试这个:
if( typeof getComputedStyle == "undefined")
getComputedStyle = function(elm) {return elm.currentStyle;}
elem.style.color = getComputedStyle(elem.parentNode).color;
这将获得父节点的计算样式(旧IE中的currentStyle
),这与inherit
基本相同。