반응형
코딩할때 자주쓰는 onkey 이벤트들의 차이점.
onkeypress : 키를 눌렀을때(F1, ctrl, alt등 직접 입력이 되지않는 버튼에는 동작하지 않는다)
onkeydown: 키를 눌렀을때(키를 눌렀을때 반응하기 때문에 글자가 써지기 전에 alert이 먼저 뜨는걸 볼수있다. 그렇기 때문에 한템포 늦게 반응하는것 처럼 보인다)
onkeyup : 키를 눌렀다 땠을때
<html>
<head>
</head>
<body>
onKeyup : <input type="text" onkeyup="alert(this.value);" /><br />
onKeydown : <input type="text" onKeydown="alert(this.value);" /><br />
onKeypress : <input type="text" onkeypress="alert(this.value);" />
</body>
</html>
반응형
'웹개발 > javascript' 카테고리의 다른 글
[javascript] 몇 초후에 실행 setTimeout (0) | 2016.11.09 |
---|---|
[javascript]동적으로 css(style) 변경하기 (0) | 2016.03.10 |
[javascript]바이트 체크하기 (0) | 2015.06.14 |
[javascript]예 아니오(confirm) (0) | 2014.04.01 |
[javascript]반복(setInterval) (0) | 2013.12.18 |