Phương thức CSSStyleDec Tuyên bố setProperty ()
❮ Đối tượng CSSStyleDec Tuyên bố
Thí dụ
Đặt thuộc tính CSS mới:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow");
Định nghĩa và Cách sử dụng
Phương thức setProperty () đặt một thuộc tính CSS mới hoặc sửa đổi một thuộc tính CSS hiện có trong một khối khai báo CSS.
Hỗ trợ trình duyệt
Method | |||||
---|---|---|---|---|---|
setProperty() | Yes | 9.0 | Yes | Yes | Yes |
Cú pháp
object.setProperty(propertyname, value, priority)
Giá trị tham số
Parameter | Description |
---|---|
propertyname | Required. A String representing the name of the property to set |
value | Optional. A String representing the new value |
priority | Optianal. A String representing if the property's priority should be set to
important or not. Legal values: "important" undefined "" |
Chi tiết kỹ thuật
Phiên bản DOM: | Mô hình đối tượng CSS |
---|---|
Giá trị trả lại: | chưa xác định |
Các ví dụ khác
Thí dụ
Đặt thuộc tính CSS mới có giá trị đặc biệt "quan trọng":
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow", "important");
Thí dụ
Sửa đổi thuộc tính CSS hiện có:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("color",
"blue");
❮ Đối tượng CSSStyleDec Tuyên bố