blob: 591412dda3c5e1ba14d6f562c98f8751bcf62141 (
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
|
---
title: MouseEvent.which
slug: Web/API/MouseEvent/which
tags:
- API
- 只读
- 非标准
- 鼠标事件
translation_of: Web/API/MouseEvent/which
---
<p>{{APIRef("DOM Events")}}</p>
<p>{{Non-standard_header}}</p>
<p>只读属性 <strong>MouseEvent.which</strong> 显示了鼠标事件是由哪个鼠标按键被按下所触发的。其他获得该信息的标准属性是 {{ domxref("MouseEvent.button") }} 与 {{ domxref("MouseEvent.buttons") }} 。</p>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">var buttonPressed = instanceOfMouseEvent.which
</pre>
<h3 id="返回值">返回值</h3>
<p>表示一个特定按键的数字:</p>
<ul>
<li><code>0</code>: 无</li>
<li><code>1</code>: 左键</li>
<li><code>2</code>: 中间滚轮(如果有的话)</li>
<li><code>3</code>: 右键</li>
</ul>
<p>如果鼠标被设置为适用于左利手人士使用,那么引发的动作恰好相反。在这种情况下,该值应该从右往左看。</p>
<h2 id="规范">规范</h2>
<p>无规范定义该属性。</p>
<h2 id="Browser_compatibility" name="Browser_compatibility">浏览器兼容性</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Edge</th>
<th>Firefox (Gecko)</th>
<th>Chrome</th>
<th>Internet Explorer</th>
<th>Opera</th>
<th>Safari</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatGeckoDesktop(1)}}<sup>[1]</sup></td>
<td>1.0</td>
<td>9.0</td>
<td>5.0</td>
<td>1.0</td>
</tr>
</tbody>
</table>
</div>
<div id="compat-mobile">
<table class="compat-table">
<tbody>
<tr>
<th>Feature</th>
<th>Edge</th>
<th>Firefox Mobile (Gecko)</th>
<th>Android</th>
<th>IE Mobile</th>
<th>Opera Mobile</th>
<th>Safari Mobile</th>
</tr>
<tr>
<td>Basic support</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{ CompatGeckoMobile(1) }} [1]</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
<td>{{CompatVersionUnknown}}</td>
</tr>
</tbody>
</table>
</div>
<p>[1] 在 {{event("mousemove")}} 事件对象上, <code>which</code> 属性被错误地设定为 <code>1</code> {{bug(1048294)}}.</p>
<h2 id="See_also" name="See_also">相关内容</h2>
<ul>
<li>{{ domxref("MouseEvent") }}</li>
</ul>
|