Binary World

jQuery 이벤트(event) 02 본문

개발자의 길/jQuery

jQuery 이벤트(event) 02

모쿠 2017. 4. 10. 15:03

<jQuery의 이벤트>


<04_event2.html>


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
46
47
48
49
50
51
52
53
54
55
56
57
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>jQuery</title>
<style type="text/css">
{
    border: 1px solid grey;
    width: 200px;
    height: 200px;
    background-color: lightgreen;
    font-size: 200%;
    text-align: center;
}
</style>
 
<!-- jQuery CDN 포함: 라이브러리 포함 -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js">
</script>
<script>
$(document).ready(function() {
    // $('selector').event(function() {});
    // 하나의 HTML 요소에 여러개의 event handler를 등록
    // $('selector').on({
    //      event1: function() {},
    //      event2: function() {},
    //    ...
    // });
    $('p').on({
        mouseover: function() {
            $(this).css('background-color''lightyellow');
        },
        mouseout: function() {
            $(this).css('background-color''lightgreen');
        },
        click: function() {
            if($(this).text().match('TEST')){
            $(this).text('안녕');
            } else {
                $(this).text('TEST');
            }
        }
    });
    
});
 
</script>
 
</head>
<body>
 
<h1>jQuery Event 2</h1>
<p>TEST</p>
 
 
</body>
</html>
cs



<출력화면>


- 실행전

- 실행후



'개발자의 길 > jQuery' 카테고리의 다른 글

jQuery CSS 변경  (0) 2017.04.10
jQuery getter/setter  (0) 2017.04.10
jQuery 이벤트(event) 01  (0) 2017.04.10
jQuery 기본 문법  (0) 2017.04.10
jQuery 사용하기  (0) 2017.04.10
Comments