1. onmouseover
- 마우스 커서를 올리는 순간 이벤트 발생
2. onmouseout
- 마우스 커서를 떼는 순간 이벤트 발생
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>onmouseover/onmouseout</title>
<style type="text/css">
a{
color:white;
text-decoration:none;
}
td{
width:100px;
margin-top:10px;
text-align:center;
background-color: #ff8888;
}
</style>
<script type="text/javascript">
function changeBgColor(cell, newColor){
cell.style.backgroundColor=newColor;
}
</script>
</head>
<body>
<table>
<tr>
<!-- this는 이벤트가 발생한 태그를 의미 -->
<td onmouseover="changeBgColor(this,'#FF0000');" onmouseout="changeBgColor(this,'#ff8888');">
<a href="#">menu01</a>
</td>
</tr>
<tr>
<td onmouseover="changeBgColor(this,'#FF0000');" onmouseout="changeBgColor(this,'#ff8888');">
<a href="#">menu02</a>
</td>
</tr>
<tr>
<td onmouseover="changeBgColor(this,'#FF0000');" onmouseout="changeBgColor(this,'#ff8888');">
<a href="#">menu03</a>
</td>
</tr>
</table>
</body>
</html>
|
cs |
3.onhange
-input text 내용 변경을 감지하여 이벤트 처리
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>onchange</title>
<script type="text/javascript">
function sub(){
var x = document.getElementById('name');
//대문자로 변경해서 입력창에 표시
x.value=x.value.toUpperCase();
}
</script>
</head>
<body>
영어단어 : <input type="text" id="name" onchange="sub();">
<p>입력필드를 벗어나면 대문자로 변경됩니다.</p>
</body>
</html>
|
cs |
4. onsubmit
- 전송버튼 클릭 시 이벤트 처리
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>onsubmit</title>
<script type="text/javascript">
function check(){
if(document.member.id.value==''){
alert('id를 입력하세요!');
document.member.id.focus();
return false; //false값이 반환되면 submit이 안된다.
}
if(document.member.password.value==''){
alert('비밀번호를 입력하세요!');
document.member.password.focus();
return false; //false값이 반환되면 submit이 안된다.
}
}
</script>
</head>
<body>
<!-- form에서 이벤트가 발생되므로 form에 적용해야한다.
return되는 값을 받아야하므로 return을 명시한다.-->
<form name="member" action="a.jsp"method="post" onsubmit="return check();">
id <input type="text" name="id"> <br>
비밀번호 <input type="password" name="password"><br>
<input type="submit" value="확인">
<input type="reset" value="초기화">
</form>
</body>
</html>
|
cs |
'프로그래밍 > 자바스크립트' 카테고리의 다른 글
[자바스크립트] 이벤트 : key 이벤트 (0) | 2021.07.28 |
---|---|
[자바스크립트] 이벤트 : script에서 이벤트 연결 (0) | 2021.07.28 |
[자바스크립트]이벤트 : 이벤트 처리 방법 (0) | 2021.07.27 |
[자바스크립트]DOM : 문서 객체 제거(removeChild) (0) | 2021.07.27 |
[자바스크립트]DOM : innerHTML, 문서 객체의 스타일 처리 (0) | 2021.07.27 |