aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/uievent/which/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/api/uievent/which/index.html')
-rw-r--r--files/zh-cn/web/api/uievent/which/index.html102
1 files changed, 102 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/uievent/which/index.html b/files/zh-cn/web/api/uievent/which/index.html
new file mode 100644
index 0000000000..b94bab0616
--- /dev/null
+++ b/files/zh-cn/web/api/uievent/which/index.html
@@ -0,0 +1,102 @@
+---
+title: KeyboardEvent.which
+slug: Web/API/UIEvent/which
+tags:
+ - Code
+ - DOM
+ - Key
+ - KeyboardEvent
+ - keyCode
+ - which
+translation_of: Web/API/KeyboardEvent/which
+original_slug: Web/API/KeyboardEvent/which
+---
+<div>{{ APIRef("DOM Events") }} {{Deprecated_header}}</div>
+
+<p>{{domxref("KeyboardEvent")}} 接口的 <code><strong>which</strong></code> 只读属性返回所按下键的数字 <code>keyCode </code>或所按下字母数字键的字符代码 (<code>charCode</code>) 。</p>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox notranslate">var <em>keyResult</em> = <em>event</em>.which;
+</pre>
+
+<h3 id="返回值">返回值</h3>
+
+<ul>
+ <li><code>keyResult</code> contains the numeric code for a particular key pressed, depending on whether an alphanumeric or non-alphanumeric key was pressed. Please see {{domxref("KeyboardEvent.charCode")}} and {{domxref("KeyboardEvent.keyCode")}} for more details.</li>
+</ul>
+
+<h2 id="例子">例子</h2>
+
+<pre class="brush: html notranslate">&lt;html&gt;
+&lt;head&gt;
+&lt;title&gt;charCode/keyCode/which example&lt;/title&gt;
+
+&lt;script type="text/javascript"&gt;
+
+function showKeyPress(evt) {
+alert("onkeypress handler: \n"
+ + "keyCode property: " + evt.keyCode + "\n"
+ + "which property: " + evt.which + "\n"
+ + "charCode property: " + evt.charCode + "\n"
+ + "Character Key Pressed: "
+ + String.fromCharCode(evt.charCode) + "\n"
+ );
+}
+
+
+function keyDown(evt) {
+alert("onkeydown handler: \n"
+ + "keyCode property: " + evt.keyCode + "\n"
+ + "which property: " + evt.which + "\n"
+ );
+}
+
+&lt;/script&gt;
+&lt;/head&gt;
+
+&lt;body
+ onkeypress="showKeyPress(event);"
+ onkeydown="keyDown(event);"
+&gt;
+
+&lt;p&gt;Please press any key.&lt;/p&gt;
+
+&lt;/body&gt;
+&lt;/html&gt;
+</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <thead>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ </thead>
+ <tbody>
+ <tr>
+ <td>{{SpecName('DOM3 Events','#legacy-interface-KeyboardEvent','KeyboardEvent.which')}}</td>
+ <td>{{Spec2('DOM3 Events')}}</td>
+ <td>Initial definition; specified as deprecated</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("api.KeyboardEvent.which")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li>{{domxref("KeyboardEvent")}}, the interface this property belongs too.</li>
+</ul>
+
+<div id="gtx-trans" style="position: absolute; left: 458px; top: 1890px;">
+<div class="gtx-trans-icon"></div>
+</div>