javascript - getPropertyValue ("backgroundColor") 返回一个空字符串

标签 javascript css background-color getproperty getcomputedstyle

这是我的问题:

var mycss = window.getComputedStyle(myelement);

返回一个 CSSStyleDeclaration 对象:

CSSStyleDeclaration {0: "animation-delay",..., backgroundColor: "rgb(0, 0, 0)",...}

console.log(mycss);

然后,我想获取背景颜色,但是

mycss.getPropertyValue("backgroundColor");

返回空字符串 ""!

为什么??

最佳答案

代替

mycss.getPropertyValue("backgroundColor");

使用

mycss.getPropertyValue('background-color')

这对我有用。

关于javascript - getPropertyValue ("backgroundColor") 返回一个空字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48306795/

相关文章:

HTML 在同一行左右对齐文本

html - 当 css 过滤器应用于父转换时图像不显示

qt - 如何设置行的背景颜色?

c# - 更改 Windows 8 手机中的 xaml 网格背景 C#

html - 如何创建具有双色背景的表格单元格?

javascript - 更改幻灯片时如何获取当前幻灯片的索引?

javascript - 快速路线不起作用?

html - 如何使用 twitter bootstrap 右对齐元素?

javascript - ASCII 表,其中字段可以有换行符

javascript inheritFrom 与原型(prototype)