자바스크립트 정리 7 (이벤트)

## 이벤트

1. 이벤트 뛰우기 예제


ex1) 버튼 클릭시 경고창 뜨는 예제

<html>
<head>
<script>
function test(){
alert("goodjob!!");
}
</script>
</head>
<body>
<input type="button" value="click" onclick="test();"/>
</body>
</html>

 

ex2) 버튼 누르면 구구단의 9단을 반복하도록 하는 예제
<html>
<head>
<script>
var test=0;
</script>
</head>
<body>
<input type="button" value="click" onclick="i=9;test++;result=test*i;alert('9곱하기'+test+'는'+result);" />
</body>
</html>


=> 누를때 마다 구단 진행

 

2. 이벤트 종류
- 클릭
1) 클릭 이벤트: onclick (대부분 지원)
2) 더블클릭 이벤트: ondblclick (대부분 지원)

 

- 포커스
3) 포커스를 얻을때: onfocus (<button>, <input>, <label>, <select>, <textarea>, <body>)
4) 포커스를 읽을때: onblur (<button>, <input>, <label>, <select>, <textarea>, <body>)

 

ex) 포커스 얻을때, 읽을때
<html>
<body>
<input type="textaea" onfocus="alert('on')" onblur="alert('off')" />
</body>
</html>

 

- 마우스
5) 마우스 버튼 늘렀을때 : onmousedown (대부분 지원)
6) 마우스 버튼 땟을때 : onmouseup (대부분 지원)
7) 마우스 움직였을때 : onmousemove (대부분 지원)
8) 마우스를 요소밖으로 움직였을때 : onmouseout (대부분 지원)
9) 마우스를 요소위로 움직였을때 : onmouseover (대부분 지원)

 

 

## 더 많은 자바스크립트 이벤트 보기 ↓↓↓↓↓↓↓

 ▶ http://www.technote.co.kr/php/technote1/board.php?board=apple2&command=body&no=257

설정

트랙백

댓글