• 코드:
​x
 
1
<!DOCTYPE html>
2
<html lang="ko">
3
​
4
<head>
5
    <meta charset="UTF-8">
6
    <title>jQuery Event Method</title>
7
    <script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
8
    <script>
9
        $(function() {
10
            // 아이디가 "focus"인 요소에 focusin 이벤트를 설정함.
11
            $("#focus").on("focusin", function(event) {
12
                $(this).css("backgroundColor", "yellow");
13
            });
14
            // 아이디가 "focus"인 요소에 focusout 이벤트를 설정함.
15
            $("#focus").on("focusout", function(event) {
16
                $(this).css("backgroundColor", "white");
17
            });
18
        });
19
    </script>
20
</head>
21
​
22
<body>
23
​
24
    <h1>.focusin()과 .focusout() 메소드</h1>
25
​
26
    <p>아래 텍스트 필드를 마우스로 클릭해 보세요!</p>
27
    <input type="text" id="focus">
28
    
29
</body>
30
​
31
</html>