Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> HTML

Thuộc tính metaKey của KeyboardEvent trong HTML DOM

Thuộc tính metaKey của KeyboardEvent trong HTML DOM trả về giá trị Boolean (true/false) tương ứng với việc phím Meta (Command/Windows) có được nhấn trong một sự kiện hay không.

Cú pháp

Trả về booleanValue:

event.metaKey

Ví dụ

Ví dụ minh họa thuộc tính KeyboardEvent metaKey:

<!DOCTYPE html> <html> <head> <title>KeyboardEvent metaKey</title> <style> form { width:70%; margin: 0 auto; text-align: center; } * { padding: 2px; margin:5px; } input[type="button"] { border-radius: 10px; } </style> </head> <body> <form> <fieldset> <legend>KeyboardEvent-metaKey</legend> <label>Biên tập: <input type="text" id="textSelect" onkeydown="getEventData(event)" autocomplete="off"> </label> <div id="divDisplay">Tôi thách bạn nhấn phím Meta</div> </fieldset> </form> <script> var divDisplay = document.getElementById("divDisplay"); var textSelect = document.getElementById("textSelect"); function getEventData(InputEvent) { if(InputEvent.metaKey === true) divDisplay.textContent = 'You are very brave!'; else divDisplay.textContent = 'You scared enough?'; } </script> </body> </html>

Kết quả

Trước khi nhập bất kỳ ký tự nào:

Thuộc tính metaKey của KeyboardEvent trong HTML DOM

Sau khi nhập đáp án sai:

Thuộc tính metaKey của KeyboardEvent trong HTML DOM

Sau khi nhập đáp án đúng:

Thuộc tính metaKey của KeyboardEvent trong HTML DOM