键盘事件:altKey 属性
KeyboardEvent.altKey
只读属性是一个布尔值,指示当事件发生时 alt 键(在 macOS 上为 Option 或 ⌥)是否被按下 (true
) 或未被按下 (false
)。
值
一个布尔值。
示例
html
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>altKey example</title>
<script>
function showChar(e) {
alert(
"Key KeyDown: " +
String.fromCharCode(e.charCode) +
"\n" +
"charCode: " +
e.charCode +
"\n" +
"ALT key KeyDown: " +
e.altKey +
"\n",
);
}
</script>
</head>
<body onkeydown="showChar(event);">
<p>
Press any character key, with or without holding down the ALT key.<br />
You can also use the SHIFT key together with the ALT key.
</p>
</body>
</html>
规范
规范 |
---|
UI 事件 # dom-keyboardevent-altkey |
浏览器兼容性
BCD 表格仅在启用 JavaScript 的浏览器中加载。