CSSStyleDeclaration setProperty() 方法
示例
設定新的 CSS 屬性
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color", "yellow");
自己動手試一試 »
描述
setProperty() 方法用於在 CSS 宣告塊中設定一個新 CSS 屬性或修改一個現有的 CSS 屬性。
瀏覽器支援
方法 | |||||
---|---|---|---|---|---|
setProperty() | 是 | 9.0 | 是 | 是 | 是 |
語法
object.setProperty(propertyname, value, priority)
引數值
引數 | 描述 |
---|---|
propertyname | 必需。表示要設定的屬性名稱的字串 |
value | 必需。表示新值的字串 |
priority | 可選。表示是否應將屬性的優先順序設定為 important 的字串。 合法值 "important" undefined "" |
技術詳情
DOM 版本 | CSS 物件模型 |
---|---|
返回值 | undefined |
更多示例
示例
使用 "important" 優先順序設定新的 CSS 屬性
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color", "yellow", "important");
自己動手試一試 »
示例
修改現有的 CSS 屬性
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color", "blue");
自己動手試一試 »
❮ CSSStyleDeclaration 物件