HTML DOM中的KeyboardEvent shiftKey屬性是隻讀屬性,用於返回一個布爾值,該布爾值指示是否按下SHIFT鍵。如果按下SHIFT鍵,則KeyboardEvent shiftKey屬性返回true,否則返回false。
用法:
event.shiftKey
以下示例程序旨在說明HTML DOM中的KeyboardEvent shiftkey屬性:
例:本示例檢查是否按下了SHIFT鍵。
<!DOCTYPE html>
<html>
<head>
<title>
HTML DOM KeyboardEvent shiftKey Property
</title>
</head>
<body>
<h1>GeeksforGeeks</h1>
<h2>KeyboardEvent shiftKey Property</h2>
<p>
Check whether the SHIFT key is pressed or not
</p>
<input type="text" onkeydown="keyboard(event)">
<p id="test"></p>
<!-- script to check shift key is pressed or not -->
<script>
function keyboard(event) {
var a = document.getElementById("test");
if (event.shiftKey) {
a.innerHTML = "The Shift key has been pressed!";
}
else {
a.innerHTML = "The Shift key has not been pressed!";
}
}
</script>
</body>
</html>
輸出:
之前按鍵:
之後按鍵:
支持的瀏覽器:下麵列出了KeyboardEvent shiftKey屬性支持的瀏覽器:
- Opera
- IE瀏覽器
- 穀歌瀏覽器
- Firefox
- 蘋果Safari
相關用法
- HTML TouchEvent shiftKey用法及代碼示例
- HTML KeyboardEvent which用法及代碼示例
- HTML KeyboardEvent key用法及代碼示例
- HTML KeyboardEvent altKey用法及代碼示例
- HTML keyboardEvent charCode用法及代碼示例
- HTML KeyboardEvent code用法及代碼示例
- HTML KeyboardEvent keyCode用法及代碼示例
- HTML KeyboardEvent metaKey用法及代碼示例
- HTML KeyboardEvent location用法及代碼示例
- javascript MouseEvent shiftKey用法及代碼示例
- HTML DOM KeyboardEvent getModifierState()用法及代碼示例
- HTML DOM value用法及代碼示例
- HTML DOM id用法及代碼示例
- HTML DOM specified用法及代碼示例
注:本文由純淨天空篩選整理自Shubrodeep Banerjee大神的英文原創作品 HTML | DOM KeyboardEvent shiftKey Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。