CSSStyleDeclaration.getPropertyValue()

CSSStyleDeclaration.getPropertyValue() 接口返回一个 DOMString ,其中包含请求的CSS属性的值。

语法

var value = style.getPropertyValue(property);

参数

  • property 是一个 DOMString,是需要查询的CSS 属性名称。

返回值

  • value 是 DOMString ,包含查找属性的值。若对应属性没有设置,则返回空字符串。

示例

下述示例使用一个CSS选择器规则查询对应的margin 属性的值:

var declaration = document.styleSheets[0].cssRules[0].style;
var value = declaration.getPropertyValue('margin'); // "1px 2px"

规范

规范 状态
CSS Object Model (CSSOM)
CSSStyleDeclaration.getPropertyValue()
Working Draft
Document Object Model (DOM) Level 2 Style Specification
CSSStyleDeclaration
Obsolete

浏览器兼容性

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
getPropertyValueChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support YesOpera Full support YesSafari Full support 6WebView Android Full support 4.4Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 1.0

Legend

Full support  
Full support