From fdc77da2ba02ff78b23fc129ec7ee20c0fa28afb Mon Sep 17 00:00:00 2001 From: MDN Date: Thu, 9 Sep 2021 00:49:39 +0000 Subject: [CRON] sync translated content --- files/zh-cn/web/api/uievent/which/index.html | 102 +++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 files/zh-cn/web/api/uievent/which/index.html (limited to 'files/zh-cn/web/api/uievent/which') 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 +--- +
{{ APIRef("DOM Events") }} {{Deprecated_header}}
+ +

{{domxref("KeyboardEvent")}} 接口的 which 只读属性返回所按下键的数字 keyCode 或所按下字母数字键的字符代码 (charCode) 。

+ +

语法

+ +
var keyResult = event.which;
+
+ +

返回值

+ + + +

例子

+ +
<html>
+<head>
+<title>charCode/keyCode/which example</title>
+
+<script type="text/javascript">
+
+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"
+     );
+}
+
+</script>
+</head>
+
+<body
+ onkeypress="showKeyPress(event);"
+ onkeydown="keyDown(event);"
+>
+
+<p>Please press any key.</p>
+
+</body>
+</html>
+
+ +

规范

+ + + + + + + + + + + + + + + + +
SpecificationStatusComment
{{SpecName('DOM3 Events','#legacy-interface-KeyboardEvent','KeyboardEvent.which')}}{{Spec2('DOM3 Events')}}Initial definition; specified as deprecated
+ +

浏览器兼容性

+ + + +

{{Compat("api.KeyboardEvent.which")}}

+ +

See also

+ + + +
+
+
-- cgit v1.2.3-54-g00ecf