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

[DOM_Event] JS - focusout 이벤트 (= onfocusout 속성) - 해당요소(또는 자식요소) 포커스 잃을 때 이벤트 발생. (= onfocusout이벤트 = 온포커스아웃 이벤트)

목차

  1. focusout() 예제 - 포커스 잃을 때 영문을 대문자로 자동 변환
  2. focusout() 정의
  3. focusout() 구문
  4. focusout() 예제 - (onfocusin / onfocusout) 이벤트 함께 걸 때
  5. focusout() 예제 - (focus / blur) 이벤트를 addEventListener() 메서드로 걸 때
  6. focusout() 예제 - (focusin / focusout) 이벤트를 addEventListener() 메서드로 걸 때


focusout() 예제 - 포커스 잃을 때 영문을 대문자로 자동 변환

 

<input type="text" id="hz" onfocusout="homzzang()">


<script>

function homzzang() {

  var x = document.getElementById("hz");

  x.value = x.value.toUpperCase();

}

</script>

 

결과보기

 

focusout() 정의

 

요소가 포커스 잃을 때 이벤트 발생.

 


 

1.

onblur 이벤트와 유사하나 아래와 같은 차이점 존재.

  • onblur 이벤트 : 이벤트 확산 X
  • onfocusout 이벤트 : 이벤트 확산 O

∴ 요소 또는 해당 자식이 포커스 잃는지 확인하려면 onfocus

 

2.

focusout 이벤트의 반대는 focusin 이벤트임.

 

3.

  • (HTML / JS)의 속성으로 사용할 경우: onfocusout 형태
  • JS addEventListener() 메서드의 매개변수 경우: focusout 형태

 

4.

  • 이벤트확산: O
  • 취소가능성: X
  • 이벤트타입: FocusEvent
  • 지원HTML: 모든 HTML 요소 (단, <base>, <bdo>, <br>, <head>, <html>, <iframe>, <meta>, <param>, <script>, <style>, <title> 요소는 제외)
  • DOM 버전: Level 2 Events

 

5.

주요 브라우저 모두 지원.

[주의] onfocusout JS속성 방식 경우 오작동 할 수도 있으니, HTML 속성 방식이나 addEventListener() JS메서드 방식 이용해야 함.

 

 

focusout() 구문

 

HTML 속성 방식

<element onfocusout="myScript">

 

JS 속성 방식 (주의: Chrome, Safari, Opera 15+ 등에서 오작동 가능)

object.onfocusout = function(){myScript};

 

JS 매서드 방식

object.addEventListener("focusout", myScript);

 

 

focusout() 예제 - (onfocusin / onfocusout) 이벤트 함께 걸 때

 

<input type="text" id="hz" onfocusin="focusCase()" onfocusout="blurCase()">


<script>

function focusCase() {

  document.getElementById("hz").style.background = "yellow";

}


function blurCase() {

  document.getElementById("hz").style.background = "red";

}

</script>

 

결과보기

 

focusout() 예제 - (focus / blur) 이벤트를 addEventListener() 메서드로 걸 때

※ 주의: (focus/blur) 이벤트 경우 기본적으로 이벤트 확산 안 하므로, addEventListener() 매서드의 useCapture 매개변수를 true로 설정 필요.

 

<form id="hzform">

  <input type="text" id="hz">

</form>


<script>

var x = document.getElementById("hzform");

x.addEventListener("focus", focusCase, true);

x.addEventListener("blur", blurCase, true);


function focusCase() {

  document.getElementById("hz").style.backgroundColor = "yellow";  

}


function blurCase() {

  document.getElementById("hz").style.backgroundColor = "";  

}

</script>

 

결과보기

 

focusout() 예제 - (focusin / focusout) 이벤트를 addEventListener() 메서드로 걸 때

※ 주의: (focusin / focusout) 이벤트 경우 기본적으로 이벤트 확산하므로, addEventListener() 메서드의 useCapture 매개변수를 true로 설정할 필요 없음.

 

<form id="hzform">

  <input type="text" id="hz">

</form>


<script>

var x = document.getElementById("hzform");

x.addEventListener("focusin", focusCase);

x.addEventListener("focusout", blurCase);


function focusCase() {

  document.getElementById("hz").style.backgroundColor = "yellow";  

}


function blurCase() {

  document.getElementById("hz").style.backgroundColor = "";  

}

</script>

 

결과보기


 

분류 제목
DOM_Event JS - Event 종류 ★ - 이벤트부착 / 이벤트종류 / 이벤트속성 / 이벤트메서드
DOM_Event JS - abort 이벤트 (= onabort 속성) - 미디어로드중단 (= 온어보트이벤트, IE9)
DOM_Event JS - afterprint 이벤트 (= onafterprint 속성) - 인쇄모드이벤트 (= 인쇄시작 / …
DOM_Event JS - animationend 이벤트 (= onanimationend 속성) - 애니완료이벤트 (= 애니종…
DOM_Event JS - animationiteration 이벤트 (= onanimationiteration 속성) - CS…
DOM_Event JS - animationstart 이벤트 (= onanimationstart 속성) - CSS 애니메인션 …
DOM_Event JS - beforeprint 이벤트 (= onbeforeprint 속성) - 인쇄모드 인쇄대화상자 나타나기…
DOM_Event JS - beforeunload 이벤트 (= onbeforeunload 속성) - 웹문서 언로드 (= 사이트…
DOM_Event JS - blur 이벤트 (= onblur 속성) - 포커스제거이벤트 (= 포커스해제이벤트 = 블러이벤트)
DOM_Event JS - canplay 이벤트 (= oncanplay 속성) - 동영상재생가능 (= 비디오재생가능/오디오재생…
DOM_Event JS - canplaythrough 이벤트 (= oncanplaythrough 속성) - 버퍼링중지없이 재생…
DOM_Event JS - change 이벤트 (= onchange 속성) ★ - 요소값변경이벤트 (= 체인지이벤트 = 온체인…
DOM_Event JS - click 이벤트 (= onclick속성 = 온클릭이벤트) ★ - 마우스클릭이벤트
DOM_Event JS - contextmenu 이벤트 (oncontextmenu 속성) - 마우스오른쪽메뉴선택 (= 컨텍스트…
DOM_Event JS - copy 이벤트 (= oncopy 속성) - 복사이벤트 (= copy이벤트 = 카피이벤트) ※ 복사…
DOM_Event JS - cut 이벤트 (= oncut 속성) - 잘라내기이벤트 (= 컷이벤트)
DOM_Event JS - dblclick 이벤트 (= ondblclick 속성) ★ - 마우스더블클릭이벤트
DOM_Event JS - drag 이벤트 (= ondrag 속성) - 마우스드래그이벤트 (IE9) ※ 드래그앤드롭
DOM_Event JS - dragend 이벤트 (= ondragend 속성) - 마우스드래그종료 (IE9)
DOM_Event JS - dragenter 이벤트 (= ondragenter 속성) - 드래그진입 (= 드래그엔터이벤트)
1/9
목록
찾아주셔서 감사합니다. Since 2012