MouseEvent: shiftKey 属性
MouseEvent.shiftKey 只读属性是一个布尔值,表示在给定鼠标事件发生时,shift 键是否被按下。
值
一个布尔值,其中 true 表示按下了该键,false 表示该键未按下。
示例
当您触发 click 事件时,此示例会记录 shiftKey 属性。
HTML
html
<p>Click anywhere to test the <code>shiftKey</code> property.</p>
<p id="log"></p>
JavaScript
js
let log = document.querySelector("#log");
document.addEventListener("click", logKey);
function logKey(e) {
log.textContent = `The shift key is pressed: ${e.shiftKey}`;
}
结果
规范
| 规范 |
|---|
| UI 事件 # dom-mouseevent-shiftkey |
浏览器兼容性
加载中…