Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在js中检查css颜色属性是否接受';继承';价值_Javascript - Fatal编程技术网

Javascript 在js中检查css颜色属性是否接受';继承';价值

Javascript 在js中检查css颜色属性是否接受';继承';价值,javascript,Javascript,是否有办法在javascript中检查浏览器是否接受css颜色属性的“继承”值,即object.stye.color='inherit'是否不会导致错误(在IE 7中会导致错误)。这可能有助于检测css属性: 希望对您有所帮助我为rgba颜色使用了一个技巧: try {elem.style.background = "rgba(255,255,255,0.5)";} catch(e) {elem.style.background = "#cccccc";} 您可以很容易地将其适应您的问题: t

是否有办法在javascript中检查浏览器是否接受css颜色属性的“继承”值,即
object.stye.color='inherit'
是否不会导致错误(在IE 7中会导致错误)。

这可能有助于检测css属性:


希望对您有所帮助

我为
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;

这将获得父节点的计算样式(
currentStyle
,在旧版IE中),它与继承基本相同。

谢谢。正是我需要的!如果你的问题已经得到回答,请接受答案。