The read-only property returns an integer that represents the number of style declarations in this CSS declaration block.
var num = styles.length;
An integer that provides the number of styles explictly set on the parent of the instance.
The following gets the number of explicitly set styles on the following HTML element:
<div id="div1" style="margin: 0 10px; background-color: #CA1; font-family: monospace"></div>
JavaScript code:
var myDiv = document.getElementById('div1'); var divStyle = myDiv.style; var len = divStyle.length; // 6
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
length
|
Chrome 1 | Edge 12 | Firefox 1 | IE Yes | Opera Yes | Safari 6 | WebView Android 4.4 | Chrome Android 18 | Firefox Android 4 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android 1.0 |
完整支持
CSSStyleDeclaration
length
parentRule
AnimationEvent
CSS
CSSConditionRule
CSSGroupingRule
CSSKeyframeRule
CSSKeyframesRule
CSSMediaRule
CSSNamespaceRule
CSSPageRule
CSSRule
CSSRuleList
CSSStyleRule
CSSStyleSheet
CSSSupportsRule
CaretPosition
LinkStyle
MediaQueryList
MediaQueryListListener
Screen
StyleSheet
StyleSheetList
TransitionEvent