MouseEvent: shiftKey 屬性

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

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

瀏覽器相容性

另見