设置新的 CSS 属性:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color", "yellow");
亲自试一试 »
setProperty() 方法在 CSS 声明块中设置新的 CSS 属性或修改现有的 CSS 属性。
Method | |||||
---|---|---|---|---|---|
setProperty() | Yes | 9.0 | Yes | Yes | Yes |
object.setProperty(
propertyname, value, priority)
Parameter | Description |
---|---|
propertyname | Required. A String representing the name of the property to set |
value | Required. A String representing the new value |
priority | Optional. A String representing if the property's priority should be set to important or not. Legal values: "important" undefined "" |
DOM 版本: | CSS 对象模型 |
---|---|
返回值: | 不明确的 |
设置具有 "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");
亲自试一试 »
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!