window.getComputedStyle(elem,null).getPropertyValue(“style”)和window.getComputedStyle(elem,null).style有什么区别
window.getComputedStyle(elem,null).getPropertyValue(“style”)和window.getComputedStyle(elem,null).style有什么区别
10 回答11.2k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.7k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
3 回答2.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
window.getComputedStyle(elem,null)
返回`CSSStyleDeclaration
对象这个对象有
getPropertyValue
`方法获取对应css属性的值例如
getPropertyValue('color')
;//获取字体颜色子CSSStyleDeclaration是没有style属性的
你是不是想问
window.getComputedStyle(elem,null).getPropertyValue(“color”)和window.getComputedStyle(elem,null).color有什么区别
有区别,属性值是不同的访问方式
在访问例如background-color类似格式的css属性时
`window.getComputedStyle(elem,null).background-color
就不可以了,需要使用window.getComputedStyle(elem,null).backgroundColor
访问window.getComputedStyle(elem,null).getPropertyValue(“background-color”)
是可以的