HTML DOM KeyboardEvent altKey 속성은 ALT HTML 문서에서 키 이벤트가 발생했을 때 키가 눌렸는지 여부.
구문
다음은 구문입니다 -
event.altKey
HTML KeyboardEvent altKey 속성의 예를 살펴보겠습니다-
예시
<!DOCTYPE html>
<html>
<style>
body {
color: #000;
height: 100vh;
background: linear-gradient(62deg, #FBAB7E 0%, #F7CE68 100%) no-repeat;
text-align: center;
}
input {
border: 2px solid #fff;
padding: 8px;
background: transparent;
width: 310px;
border-radius: 20px;
outline: none;
}
::placeholder {
color: #000;
}
.show {
font-size: 1.2rem;
color: #fff;
}
</style>
<body>
<h1>HTML KeyboardEvent altKey Property Demo</h1>
<input type="text" placeholder="Enter your message" onkeydown="display(event)">
<div class="show">
</div>
<script>
function display(event) {
if (event.altKey) {
document.querySelector(".show").innerHTML = "The key is " + event.key + " key";
} else {
document.querySelector(".show").innerHTML = "The key is " + event.key + " key";
}
}
</script>
</body>
</html> 출력

이제 텍스트 필드에서 아무 키나 누르기 시작하고 Alt 키를 눌렀을 때 altKey 속성이 어떻게 작동하는지 관찰하십시오-
