Skip to content

Commit

Permalink
zh-cn: update the translation of the UIEvent.which (#25057)
Browse files Browse the repository at this point in the history
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: A1lo <[email protected]>
  • Loading branch information
3 people authored Dec 14, 2024
1 parent 43dc16f commit 882d187
Showing 1 changed file with 40 additions and 30 deletions.
70 changes: 40 additions & 30 deletions files/zh-cn/web/api/uievent/which/index.md
Original file line number Diff line number Diff line change
@@ -1,58 +1,67 @@
---
title: KeyboardEvent.which
title: UIEvent:which 属性
slug: Web/API/UIEvent/which
l10n:
sourceCommit: 22080a7cc403f7f45c8e85065b182c9f0d4d383c
---

{{APIRef("UI Events")}}{{Deprecated_Header}}

{{domxref("KeyboardEvent")}} 接口的 **`which`** 只读属性返回所按下键的数字 `keyCode` 或所按下字母数字键的字符代码 (`charCode`)
{{domxref("UIEvent")}} 接口的 **`UIEvent.which`** 只读属性返回一个数字,表示按下了鼠标上的哪个按钮,或者是键盘上按下的键的 `keyCode` 或字符代码(`charCode`)的数字值

##

- `keyResult` 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.
### KeyboardEvent 的值 {{Non-standard_Inline}}

## 例子
对于 {{domxref("KeyboardEvent")}},`event.which` 包含按下的特定按键的数字代码,具体取决于是否按下了字母数字键或非字母数字键。有关更多详细信息,请参阅已弃用的{{domxref("KeyboardEvent.charCode")}} 和 {{domxref("KeyboardEvent.keyCode")}}。

> [!NOTE]
> 新代码请考虑使用 {{domxref("KeyboardEvent.key")}} 或 {{domxref("KeyboardEvent.code")}}。
### MouseEvent 的值 {{Non-standard_Inline}}

对于 {{domxref("MouseEvent")}},`event.which` 是表示给定按钮的数字:

- `0`:无按钮
- `1`:左键
- `2`:中键(如果有)
- `3`:右键

对于配置为左利手使用的鼠标,按钮操作是相反的。在这种情况下,从右到左读取值。

> [!NOTE]
> 新代码请考虑使用 {{domxref("MouseEvent.button")}}。
## 示例

```html
<html>
<html lang="zh">
<head>
<title>charCode/keyCode/which example</title>
<title>charCode/keyCode/which 示例</title>

<script type="text/javascript">
<script>
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",
`onkeypress 处理器:\n` +
`keyCode 属性:${evt.keyCode}\n` +
`which 属性:${evt.which}\n` +
`charCode 属性:${evt.charCode}\n` +
`按下的字符键:${String.fromCharCode(evt.charCode)}\n`,
);
}
function keyDown(evt) {
alert(
"onkeydown handler: \n" +
"keyCode property: " +
evt.keyCode +
"\n" +
"which property: " +
evt.which +
"\n",
`onkeydown 处理器:\n` +
`keyCode 属性:${evt.keyCode}\n` +
`which 属性:${evt.which}\n`,
);
}
</script>
</head>

<body onkeypress="showKeyPress(event);" onkeydown="keyDown(event);">
<p>Please press any key.</p>
<p>请按任意键。</p>
</body>
</html>
```
Expand All @@ -65,6 +74,7 @@ slug: Web/API/UIEvent/which

{{Compat}}

## See also
## 参见

- {{domxref("KeyboardEvent")}}, the interface this property belongs too.
- {{domxref("KeyboardEvent")}}
- {{domxref("MouseEvent")}}

0 comments on commit 882d187

Please sign in to comment.