KeyboardEvent: altKey 属性
KeyboardEvent.altKey 只读属性是一个布尔值,表示在事件发生时 alt 键(macOS 上的 Option 或 ⌥)是否被按下(true)或未被按下(false)。
值
一个布尔值。
示例
html
<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>
<pre id="output"></pre>
js
const output = document.getElementById("output");
function showChar(e) {
output.textContent = `Key KeyDown: "${e.key}"
ALT key KeyDown: ${e.altKey}
`;
}
document.addEventListener("keydown", showChar);
规范
| 规范 |
|---|
| UI 事件 # dom-keyboardevent-altkey |
浏览器兼容性
加载中…