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
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="utf-8">
<script src="js/jquery.js"></script>
</head>
<button>click이벤트버튼</button><br>
<button>첫번째click이벤트제거버튼</button>
<body>
<script>
 
    //event[.namespaces ]
    //namespaces는 1depth 이상 "click.a.b.c" 형식으로도 지정이 가능하다.
 
    // click이벤트버튼에 3개의 click이벤트를 각각 다른이름의 네임스페이스로 바인딩 하였다.
    $("button:eq(0)").on({
        "click.one" : function(){
            console.log("첫번째클릭이벤트")
        },
        "click.two" : function(){
            console.log("두번째클릭이벤트")
        },
        "click.three" : function(){
            console.log("세번째클릭이벤트")
        }                        
    });
 
    //button:eq(0)의 click이벤트중 "one"이라는 네임스페이스를 가진 이벤트를 제거 
    $("button:eq(1)").click(function() {
        $("button:eq(0)").off("click.one");
    }
 
</script>
</body>
</html>


반응형
Posted by 힘없는염소