2017-03-24 12 views
1

group1 입력에서 group2 입력으로 이동하면 흐림 이벤트가 감지되어 추가 작업을 수행 할 수 있습니다. 흐림 이벤트가 부모의 위쪽으로 전파되지 않습니까?부모 요소에서 흐림 이벤트를 catch하는 방법

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script> 
 
<html> 
 
    <head>  
 
    <script type="text/javascript"> 
 
    $(document).ready(function() { 
 
     $("[data-id=container]").on("blur", function() { 
 
     alert("Blur caught in parent"); 
 
     }); 
 
    }); 
 
    </script> 
 
    </head> 
 
    <body> 
 
    <div data-id="container" style="border: 1px solid gray;"> 
 
     Group 1   
 
     <input type="text" /> 
 
     <input type="text" /> 
 
     <input type="text" /> 
 
    </div> 
 
    <div data-id="container" style="border: 1px solid gray;"> 
 
     Group 2  
 
     <input type="text" /> 
 
     <input type="text" /> 
 
     <input type="text" /> 
 
    </div> 
 
    </body> 
 
</html>

+0

그룹 1 http://stackoverflow.com/questions/1259716/how-to-blur-the-div-element – Satpal

+0

보고 2 형제가 아닌 부모입니다 -> 아이 –

답변

0

나는 완전히 질문을 이해 할 수없는,하지만 당신은 나는 다음과 같은 코드를 작성하고 그룹 2 그룹 1에서 변경하면 검증의 형태를 갖고 싶어한다고 가정. 다음 스 니펫은 필요에 맞게 사용자 정의 할 수있는 일반적인 형식입니다.

   <input type="text" id="one" onblur="validate"> 
       <input type="text" id="two" onblur="validate"> 
       <input type="text" id="three" onblur="validate"> 
       <script type="text/javascript> 
        function validate() 
        { 
         var a = document.getElementById("one"); 
         var b = document.getElementById("two"); 
         var c = document.getElementById("three"); 
         if (b.hasFocus() == true) //checks if the second input box has focus 
         { 
          alert("Value of the focused field is "+a.value); //this will give you the value in the first input box 
         } 
         else if (c.hasFocus() == true) //checks if the third input box has focus 
         { 
          a.focus(); //this will get the focus back on the first input box 
         } 
        } 

       </script>