aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/event.altkey/index.html
blob: fb69717e99470d52426694ded3d07136361eb2d4 (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
---
title: event.altKey
slug: Web/API/event.altKey
translation_of: Web/API/MouseEvent/altKey
translation_of_original: Web/API/event.altKey
---
<p>{{ ApiRef() }}</p>
<h3 id="Summary" name="Summary">概述</h3>
<p>表明当事件触发时,ALT键是否处于按下的状态.</p>
<h3 id="Syntax" name="Syntax">语法</h3>
<pre class="eval">event.altKey
</pre>
<h3 id="例子">例子</h3>
<pre><code><em>var bool</em> = event.altKey;</code>
</pre>
<p>如果当事件触发时,ALT键处于按下的状态,<code style="font-family: 'Courier New','Andale Mono',monospace; font-style: normal; font-variant: normal; font-size: 100%; line-height: normal; color: inherit; font-weight: inherit;">则bool</code>的值为<code style="font-family: 'Courier New','Andale Mono',monospace; font-style: normal; font-variant: normal; font-size: 100%; line-height: normal; color: inherit; font-weight: inherit;">true,否则为</code><code style="font-family: 'Courier New','Andale Mono',monospace; font-style: normal; font-variant: normal; font-size: 100%; line-height: normal; color: inherit; font-weight: inherit;">false</code>.</p>
<pre class="brush: html">&lt;html&gt;
&lt;head&gt;
&lt;title&gt;altKey 示例&lt;/title&gt;

&lt;script type="text/javascript"&gt;

function showChar(e){
  alert(
    "按下的键: " + String.fromCharCode(e.charCode) + "\n"
    + "charCode: " + e.charCode + "\n"
    + "是否按下ALT键: " + e.altKey + "\n"
  );
}

&lt;/script&gt;
&lt;/head&gt;

&lt;body onkeypress="showChar(event);"&gt;
&lt;p&gt;
按下一个字符键,尝试同时按下ALT键.&lt;br /&gt;
你也可以同时按下SHIFT键和ALT键.
&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;
</pre>
<h3 id="规范">规范</h3>
<p>DOM Level 2 Events - property of MouseEvent object</p>
<p>{{ languages( { "ja": "ja/DOM/event.altKey", "pl": "pl/DOM/event.altKey", "en": "en/DOM/event.altKey" } ) }}</p>