MDN’s new design is in Beta! A sneak peek: https://blog.mozilla.org/opendesign/mdns-new-design-beta/

CSSStyleDeclaration

翻譯不完整。請協助 翻譯此英文文件

概要

CSSStyleDeclaration represents a collection of CSS property-value pairs. It is used in a few APIs:

屬性

CSSStyleDeclaration.cssText
Textual representation of the declaration block. Setting this attribute changes the style.
CSSStyleDeclaration.length
The number of properties. See the item method below.
CSSStyleDeclaration.parentRule
The containing CssRule.

方法

CSSStyleDeclaration.getPropertyPriority()
Returns the optional priority, "important". Example: priString= styleObj.getPropertyPriority('color')
CSSStyleDeclaration.getPropertyValue()
Returns the property value. Example: valString= styleObj.getPropertyValue('color')
CSSStyleDeclaration.item()
Returns a property name. Example: nameString= styleObj.item(0) Alternative: nameString= styleObj[0]
CSSStyleDeclaration.removeProperty()
Returns the value deleted. Example: valString= styleObj.removeProperty('color')
CSSStyleDeclaration.setProperty()
No return. Example: styleObj.setProperty('color', 'red', 'important')
CSSStyleDeclaration.getPropertyCSSValue()
Only supported via getComputedStyle. Returns an ROCSSPrimitiveValue in Firefox (CSSPrimitiveValue, in others, which implements CSSValue), or null for Shorthand properties. Example: cssString= window.getComputedStyle(elem, null).getPropertyCSSValue('color').cssText;
Note: Gecko 1.9 returns null unless using getComputedStyle().
Note: This method may be deprecated by the W3C , and it is not present in the latest CSSOM draft. It is not supported by IE and even though the function exists in Opera, calling it throws a DOMException NOT_SUPPORTED_ERR.

範例

var styleObj= document.styleSheets[0].cssRules[0].style;
alert(styleObj.cssText);
for (var i = styleObj.length-1; i >= 0; i--) {
   var nameString = styleObj[i];
   styleObj.removeProperty(nameString);
}
alert(styleObj.cssText);

備註

The declaration block is that part of the style rule that appears within the braces and that actually provides the style definitions (for the selector, the part that comes before the braces).

參見

規範

CSSOM: CSSStyleDeclaration

文件標籤與貢獻者

 此頁面的貢獻者: jackblackevo
 最近更新: jackblackevo,