MouseEvent: altKey 属性
MouseEvent.altKey 只读属性是一个布尔值,指示在发生给定鼠标事件时,alt 键是否被按下。
请注意,在某些操作系统上,浏览器无法始终检测到 alt 键。例如,在某些 Linux 版本中,左键单击与 alt 键组合用于移动或调整窗口大小。
注意: 在 Macintosh 键盘上,此键也称为 option 键。
值
一个布尔值,其中 true 表示按下了该键,false 表示该键未按下。
示例
此示例在触发 click 事件时,记录 `altKey` 属性。
HTML
html
<p>Click anywhere to test the <code>altKey</code> property.</p>
<p id="log"></p>
JavaScript
js
let log = document.querySelector("#log");
document.addEventListener("click", logKey);
function logKey(e) {
log.textContent = `The alt key is pressed: ${e.altKey}`;
}
结果
规范
| 规范 |
|---|
| UI 事件 # dom-mouseevent-altkey |
浏览器兼容性
加载中…