--- title: GlobalEventHandlers.onkeydown slug: Web/API/GlobalEventHandlers/onkeydown tags: - API - HTML DOM - NeedsContent - NeedsExample translation_of: Web/API/GlobalEventHandlers/onkeydown ---
onkeydown
속성은 현재 요소(element)의 onKeyDown
이벤트 핸들러 코드를 돌려줍니다
element.onkeydown = event handling code
This example logs the {{domxref("KeyboardEvent.code")}} value whenever you press down a key inside the {{HtmlElement("input")}} element.
<input>
<p id="log"></p>
const input = document.querySelector('input');
const log = document.getElementById('log');
input.onkeydown = logKey;
function logKey(e) {
log.textContent += ` ${e.code}`;
}
{{EmbedLiveSample("Example")}}
명세 | 상태 | 비고 |
---|---|---|
{{SpecName('HTML WHATWG','webappapis.html#handler-onkeydown','onkeydown')}} | {{Spec2('HTML WHATWG')}} |
{{Compat("api.GlobalEventHandlers.onkeydown")}}