JavaScript

[DOM_Event] JS - input 이벤트 (= oninput 속성) ★ - 입력이벤트 (= 인풋이벤트) (IE9)

목차
  1. input 예제 - 입력 이벤트
  2. input 정의
  3. input 구문
  4. input 예제 - 지정 범위 중 선택값 표시

 

input 예제 - 입력 이벤트 

 

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


<p id="demo"></p>


<script>

function homzzang() {

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

  document.getElementById("demo").innerHTML = "입력내용: " + x;

}

</script> 

 

결과보기 

 

input 정의

 

사용자가 요소에 내용 입력할 때 발생.

 


 

1.

<input> 또는 <textarea> 요소의 값이 변경 될 때 발생.

 

2. 

change 이벤트와 유사하나, 2가지 차이점 존재.
  • input 이벤트 - ① 요소값 변경 직후에 발생. ② <select> 요소에서는 작동 X.
  • change 이벤트 - ① 요소값 변경 후 요소가 포커스 잃으면 발생. ② <select> 요소에서도 작동 O.

 

3.

IE9 이상 주요 최신 브라우저 지원.

 

4.

  • 이벤트확산 : O
  • 취소가능성 : X
  • 이벤트타입 : Event , InputEvent
  • 지원 HTML : <input type="color">, <input type="date">, <input type="datetime">, <input type="email">, <input type="month">, <input type="number">, <input type="password">, <input type="range">, <input type="search">, <input type="tel">, <input type="text">, <input type="time">, <input type="url">, <input type="week"> and <textarea>
  • DOM 버전 : Level 3 Events 

 

 

input 구문

 

HTML 속성 방식

<element oninput="homzzang()"> 

 

JS 속성 방식

object.oninput = function(){homzzang()};

 

JS 메서드 방식

object.addEventListener("input", homzzang);

 

※ homzzang : 실행함수명. (함수명 자리에 실행코드를 직접 입력 가능)

※ addEventLister() 방식 주의사항 2가지 : (이벤트명에 on 안 붙임. / 실행함수명 뒤에 소괄호 안 붙임)

※ addEventListener() 메서드는 IE8 및 그 이전 브라우저는 지원 안 함.

 

input 예제 - 지정 범위 중 선택값 표시

 

<input type="range" oninput="homzzang(this.value)">                             

<p id="demo"></p>


<script>

function homzzang(val) {

  document.getElementById("demo").innerHTML = val

}

</script>

 

결과보기



분류 제목
DOM_Document JS - defaultView 속성 - 윈도우객체 (Window Object)
DOM_Document JS - designMode 속성 - 편집기능 활성화 (= 디자인모드)
DOM_Document JS - document.doctype 속성 -문서타입 (= DTD정보 = DocumentType 객체 반환…
DOM_Document JS - documentElement 속성 ★ - html요소 의미 (= 전체 웹문서 자체 = HTML 문서…
DOM_Document JS - documentMode 속성 - 문서로드IE버전 (IE전용)
DOM_Document JS - documentURI 속성 ★ - 현재웹문서위치 (= 웹문서주소)
DOM_Document JS - domain 속성 ★ - 현재웹문서의 도메인
DOM_Document JS - domConfig 속성 - 사용폐기. 돔구성
DOM_Document JS - embeds 속성 - 모든 엠베드태그 모음
DOM_Document JS - execCommand() 메서드 - 명령실행 (IE9 이상. 실험중) (예: 키보드이벤트때 실행)
DOM_Document JS - forms 속성 - 폼요소개수
DOM_Document JS - fullscreenElement 속성 - 전체화면요소 반환 (IE11 이상 접두어필요)
DOM_Document JS - fullscreenEnabled 속성 - 전체화면모드 (=풀스크린모드) 허용 (IE11 이상 접두어…
DOM_Document JS - getElementById() 메서드 ★★★ - 아이디선택자 (= 아이디로 요소얻기 = 아이디로 요…
DOM_Document JS - getElementsByClassName() 메서드 ★★ - 클래스선택자 (= 클래스명선택자 = 클…
33/89
목록
 홈  PC버전 로그인 일본어
그누앞단언어
그누뒷단언어
그외코딩언어
그누보드
제작의뢰
Q&A
커뮤니티
웹유틸
회원센터
홈짱닷컴 PC버전 로그인