getPropertyValue("backgroundColor")返回一个空字符串 [英] getPropertyValue("backgroundColor") returns an empty string
本文介绍了getPropertyValue("backgroundColor")返回一个空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的问题:
var mycss = window.getComputedStyle(myelement);
返回CSSStyleDeclaration对象:
returns a CSSStyleDeclaration object:
CSSStyleDeclaration {0: "animation-delay",..., backgroundColor: "rgb(0, 0, 0)",...}
然后,我想获取背景色,但是
Then, I want to get the background color, but
mycss.getPropertyValue("backgroundColor");
返回一个空字符串"
!
为什么?
推荐答案
在CSSStyleDeclaration中,您需要将"backgroundColor"更改为"background-color",然后调用
Within your CSSStyleDeclaration, you need to change 'backgroundColor' to 'background-color' and then call
mycss.getPropertyValue('background-color')
一个例子:HTML:
<head><style>
body {
background-color: lightblue;
}
</style>
</head>
<body id="body">
hello world
</body>
然后调用getPropertyValue:
and then calling the getPropertyValue:
var mycss = window.getComputedStyle(document.getElementById("body"));
myelement.innerHTML = mycss.getPropertyValue("background-color");
这篇关于getPropertyValue("backgroundColor")返回一个空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文