CSSStyleDeclaration.getPropertyPriority()

CSSStyleDeclaration.getPropertyPriority() 方法会根据传入的CSS属性,返回一个 DOMString 来表示该属性的优先级。

Syntax

var priority = style.getPropertyPriority(property);

参数

  • property 是一个DOMString,表示要检查的属性名。

返回值

  • priority 是一个DOMString,用以表示属性优先级。存在,就返回(例如:"important");不存在,则返回空字符串。

例子

下面的代码检查了margin,在CSS规则中是否被设置为 important 优先级。

var declaration = document.styleSheets[0].cssRules[0].style;
var isImportant = declaration.getPropertyPriority('margin') === 'important';

标准

Specification Status Comment
CSS Object Model (CSSOM)
CSSStyleDeclaration.getPropertyPriority()
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!

Feature Chrome Edge Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)
Feature Android Edge Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

文档标签和贡献者

标签: 
此页面的贡献者: woniuxingdong, mdnwebdocs-bot, Youssef-Belmeskine, joey
最后编辑者: woniuxingdong,