투케이2K

64. (jquery/제이쿼리) [event] [on] mouseenter (마우스 진입) , click (클릭) , mouseleave (마우스 떠남) 동시 이벤트 적용 실시 본문

Jquery

64. (jquery/제이쿼리) [event] [on] mouseenter (마우스 진입) , click (클릭) , mouseleave (마우스 떠남) 동시 이벤트 적용 실시

투케이2K 2022. 12. 2. 12:25
반응형

[개발 환경 설정]

개발 툴 : Edit++

개발 언어 : jquery

 

[소스 코드]

    <!-- [CDN 라이브러리 설치] -->
    <script src="https://code.jquery.com/jquery-latest.min.js"></script>





    <!-- [내부 자바스크립트 J쿼리 이벤트 지정] -->
    <script>


        /**
         * --------------------------------
         * [요약 설명]
         * --------------------------------
         * 1. load : html 최초 로드 수행 시 호출 되는 함수입니다
         * --------------------------------
         * 2. on : jquery 에서 이벤트를 적용할 때 사용합니다
         * --------------------------------
         * 3. mouseenter : 마우스 진입 이벤트를 감지 합니다
         * --------------------------------
         * 4. click : 마우스 클릭 이벤트를 감지 합니다
         * --------------------------------
         * 5. mouseleave : 진입된 마우스가 떠났을 때 이벤트를 감지 합니다
         * --------------------------------
        */



        // [html 최초 로드 및 이벤트 상시 대기 실시]
        $(window).load(function(){
            console.log("");
            console.log("=========================================");
            console.log("[window load] : [html 로드 수행 실시]");
            console.log("=========================================");
            console.log("");

            // [테스트 함수 호출]
            testMain();
        });



        // [테스트 자바스크립트 함수]
        function testMain(){
            console.log("");
            console.log("=========================================");
            console.log("[testMain] : [start]");
            console.log("=========================================");
            console.log(""); 


            // [on 사용해 이벤트 적용 실시]
            $("#divTag").on({ 
                mouseenter: function() {
                    console.log("");
                    console.log("=========================================");
                    console.log("[testMain] : [mouseenter] : 마우스 진입 발생");
                    console.log("=========================================");
                    console.log(""); 
                },

                click: function() {  
                    console.log("");
                    console.log("=========================================");
                    console.log("[testMain] : [click] : 마우스 클릭 발생");
                    console.log("=========================================");
                    console.log(""); 
                },

                mouseleave: function() {
                    console.log("");
                    console.log("=========================================");
                    console.log("[testMain] : [mouseleave] : 마우스 떠남 발생");
                    console.log("=========================================");
                    console.log(""); 
                }

            });
        };


    </script>
 

[결과 출력]


 

반응형
Comments