aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/mouseevent/buttons/index.html
blob: 7e503718a06c125525df7f2eccbe239eaf95c403 (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
---
title: MouseEvent.buttons
slug: Web/API/MouseEvent/buttons
translation_of: Web/API/MouseEvent/buttons
---
<div>{{APIRef("DOM Events")}}</div>

<div>只读属性<strong><code>MouseEvent.buttons</code></strong><code>指示事件触发时哪些鼠标按键被按下。</code></div>



<p>每一个按键都用一个给定的数(见下文)表示。如果同时多个按键被按下,buttons 的值为各键对应值做与计算(+)后的值。例如,如果右键(2)和滚轮键(4)被同时按下,buttons 的值为 2 + 4 = 6。</p>

<div class="note">
<p><strong>注意:</strong>属性 MouseEvent.button 和 MouseEvent.buttons 是不同的。MouseEvent.buttons 可指示任意鼠标事件中鼠标的按键情况,而 MouseEvent.button 只能保证在由按下和释放一个或多个按键时触发的事件中获得正确的值。</p>
</div>

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

<pre class="syntaxbox">var <em>buttonPressed</em> = <em>instanceOfMouseEvent</em>.buttons
</pre>

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

<p>一个数字,用来标识鼠标按下的一个或者多个按键。如果按下的键为多个,则值等于所有按键对应数值进行或(|)运算的结果。</p>

<ul>
 <li><code></code> : 没有按键或者是没有初始化</li>
 <li><code></code> : 鼠标左键</li>
 <li><code></code> : 鼠标右键</li>
 <li><code></code> : 鼠标滚轮或者是中键</li>
 <li><code></code> : 第四按键 (通常是“浏览器后退”按键)</li>
 <li><code>16</code> : 第五按键 (通常是“浏览器前进”)</li>
</ul>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('DOM3 Events','#widl-MouseEvent-buttons','MouseEvent.buttons')}}</td>
   <td>{{Spec2('DOM3 Events')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

{{Compat("api.MouseEvent.buttons")}}

<h2 id="See_also">See also</h2>

<ul>
 <li>{{domxref("MouseEvent")}}</li>
</ul>