此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

MouseEvent:shiftKey 属性

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

MouseEvent.shiftKey 只读属性是用于指示在某个鼠标事件发生时,shift 键是否被按下的布尔值。

布尔值,其中 true 表示按键已按下,而 false 表示按键按下。

示例

此示例会在触发 click 事件时记录 shiftKey 属性。

HTML

html
<p>单击任意位置以测试 <code>shiftKey</code> 属性。</p>
<p id="log"></p>

JavaScript

js
let log = document.querySelector("#log");
document.addEventListener("click", logKey);

function logKey(e) {
  log.textContent = `按下 shift 键:${e.shiftKey}`;
}

结果

规范

Specification
UI Events
# dom-mouseevent-shiftkey

浏览器兼容性

参见