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