aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/cssstyledeclaration/getpropertypriority/index.html
blob: a2881f7aa938b2273b26ce19ecfacea4421584e1 (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
109
110
111
112
113
114
115
116
117
118
119
---
title: CSSStyleDeclaration.getPropertyPriority()
slug: Web/API/CSSStyleDeclaration/getPropertyPriority
tags:
  - API
  - CSSDOM
  - Method
  - Reference
translation_of: Web/API/CSSStyleDeclaration/getPropertyPriority
---
<p>{{ APIRef("CSSOM") }}</p>

<p><strong>CSSStyleDeclaration.getPropertyPriority() </strong>方法会根据传入的CSS属性,返回一个 {{domxref('DOMString')}} 来表示该属性的优先级。</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">var <em>priority</em> = <em>style</em>.getPropertyPriority(<em>property</em>);</pre>

<h3 id="参数">参数</h3>

<ul>
 <li><em><code>property</code></em> 是一个{{domxref('DOMString')}},表示要检查的属性名。</li>
</ul>

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

<ul>
 <li><code><em>priority</em></code> 是一个{{domxref('DOMString')}},用以表示属性优先级。存在,就返回(例如:<code>"important"</code>);不存在,则返回空字符串。</li>
</ul>

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

<p>下面的代码检查了<code>margin</code>,在CSS规则中是否被设置为 important 优先级。</p>

<pre class="brush: js">var declaration = document.styleSheets[0].cssRules[0].style;
var isImportant = declaration.getPropertyPriority('margin') === 'important';
</pre>

<h2 id="标准">标准</h2>

<table>
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('CSSOM', '#dom-cssstyledeclaration-getpropertypriority', 'CSSStyleDeclaration.getPropertyPriority()')}}</td>
   <td>{{Spec2('CSSOM')}}</td>
   <td> </td>
  </tr>
  <tr>
   <td>{{SpecName('DOM2 Style', 'css.html#CSS-CSSStyleDeclaration', 'CSSStyleDeclaration')}}</td>
   <td>{{Spec2('DOM2 Style')}}</td>
   <td> </td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性"><strong>浏览器兼容性</strong></h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <thead>
  <tr>
   <th scope="col">Feature</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>Basic support</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>Basic support</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>