We're looking for a user researcher to understand the needs of developers and designers. Is this you or someone you know? Check out the post: https://mzl.la/2IGzdXS

CSSStyleDeclaration.getPropertyValue()

此 CSSStyleDeclaration.getPropertyValue() 接口会返回一个 DOMString ,这个返回值将会包含预请求的CSS属性信息。

语法

var value = style.getPropertyValue(property);

参数

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

返回值

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

例子

下面的例子试图在一个特定的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  

浏览器兼容性信息

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!

特性 Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
基础支持 (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
特性 Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
基础支持 (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
 

want to learn more

 

文档标签和贡献者

此页面的贡献者: 1900, xgqfrms-GitHub, lugt
最后编辑者: 1900,