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 |
瀏覽器相容性
載入中…