aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/cssstyledeclaration/length/index.html
blob: 4075f9f4a4d7188b42f4b4a951258985021fbb6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
---
title: CSSStyleDeclaration.length
slug: Web/API/CSSStyleDeclaration/length
translation_of: Web/API/CSSStyleDeclaration/length
---
<p>{{ APIRef("CSSOM") }}</p>

<p>这是一个只读的属性,它返回一个指定元素声明过的样式个数</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox">var <em>num</em> = <em>styles</em>.length;</pre>

<h3 id="值"></h3>

<p>指定元素上明确声明过的样式属性个数.</p>

<h2 id="示例">示例</h2>

<p>获取下面HTML元素明确设置过的属性个数:</p>

<pre class="brush: html">&lt;div id="div1" style="margin: 0 10px; background-color: #CA1; font-family: monospace"&gt;&lt;/div&gt;</pre>

<p>JavaScript代码:</p>

<pre>var myDiv = document.getElementById('div1'); var divStyle = myDiv.style; var len = divStyle.length; // 6</pre>

<h2 id="说明">说明</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">描述</th>
   <th scope="col">状态</th>
   <th scope="col">注释</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSSOM', '#dom-cssstyledeclaration-length', 'CSSStyleDeclaration.length')}}</td>
   <td>工作草案</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('DOM2 Style', 'css.html#CSS-CSSStyleDeclaration', 'CSSStyleDeclaration')}}</td>
   <td>废弃</td>
   <td></td>
  </tr>
 </tbody>
</table>

<p><strong>浏览器兼容性</strong></p>

<p>兼容性列表</p>

<div id="compat-desktop">
<table class="compat-table">
 <thead>
  <tr>
   <th scope="col">特性</th>
   <th scope="col">Chrome</th>
   <th scope="col">Edge</th>
   <th scope="col">Firefox (Gecko)</th>
   <th scope="col">Internet Explorer</th>
   <th scope="col">Opera</th>
   <th scope="col">Safari (WebKit)</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>基础支持</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Edge</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>基础支持</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>