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