CSSStyleDeclaration: getPropertyPriority() 方法
CSSStyleDeclaration.getPropertyPriority() 方法用於返回一個字串,該字串提供了 CSS 屬性的所有顯式設定的優先順序。
語法
js
getPropertyPriority(property)
引數
property(屬性)-
要檢查的屬性名稱字串。
返回值
表示優先順序(例如,"important")的字串,如果存在的話。如果不存在,則返回空字串。
示例
以下 JavaScript 程式碼檢查 margin 在 CSS 選擇器規則中是否被標記為 important
js
const declaration = document.styleSheets[0].cssRules[0].style;
const isImportant = declaration.getPropertyPriority("margin") === "important";
規範
| 規範 |
|---|
| CSS 物件模型 (CSSOM) # dom-cssstyledeclaration-getpropertypriority |
瀏覽器相容性
載入中…