• 회원가입
  • 로그인
  • 구글아이디로 로그인

[Event] JQ - focusout() 메서드 ★★ - 해당요소(또는 자식요소) 포커스 잃을 때 이벤트 발생. (= focusout메서드 = 포커스아웃 메서드)

목차

  1. focusout() 예제 - 포커스 잃을 때 배경색을 회색으로 변경
  2. focusout() 정의
  3. focusout() 구문

 

focusout() 예제 - 포커스 잃을 때 배경색을 회색으로 변경

 

<style>

div {border: 1px solid black;padding:10px;}

</style>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

<script>

$(document).ready(function(){

  $("div").focusin(function(){

    $(this).css("background-color", "yellow");

  });

  $("div").focusout(function(){

    $(this).css("background-color", "silver");

  });

});

</script>


<div>

  아이디: <input type="text"><br>

  닉네임: <input type="text">

</div>

 

결과보기

 

focusout() 정의

 

focusout 이벤트는 요소 (또는, 그 안의 요소)가 포커스 잃을 때 발생.

※ focusout() 메서드는 focusout 이벤트 발생 시 실행할 함수 연결함.

 


 

1. cf. 

  • blur() 메서드 - 해당 요소가 포커스 잃을 때만 발생.
  • focusout() 메서드 - 해당 요소 뿐만 아니라, 그 안의 요소가 포커스 잃을 때 도 발생.

 

2.

focusin() 메서드와 자주 사용됨.

 

 

focusout() 구문

 

$(selector).focusout(function)

 


[매개변수]

 

function

필수. focusout 이벤트 발생 시 실행할 함수 지정.

 


방문 감사합니다. (즐겨찾기 등록: Ctrl + D)

분류 제목
게시물이 없습니다.
목록
찾아주셔서 감사합니다. Since 2012