CSSStyleDeclaration setProperty () เมธอด
ตัวอย่าง
ตั้งค่าคุณสมบัติ CSS ใหม่:
var declaration = document.styleSheets[0].cssRules[0].style;
var setprop = declaration.setProperty("background-color",
"yellow");
ความหมายและการใช้งาน
เมธอด setProperty() ตั้งค่าใหม่หรือปรับเปลี่ยนคุณสมบัติ 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 | 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 "" |
รายละเอียดทางเทคนิค
รุ่น DOM: | โมเดลวัตถุ CSS |
---|---|
คืนมูลค่า: | ไม่ได้กำหนด |
ตัวอย่างเพิ่มเติม
ตัวอย่าง
ตั้งค่าคุณสมบัติ 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