본문 바로가기

Frontend/Java Script

JS event (part. 07) - 인터넷 익스플로러 이벤트 모델

인터넷 익스플로러 이벤트 모델은 다음과 같은 두 가지 메서드로 이벤트를 연결하거나 제거할 수 있다.

첫 번째 매개변수에 이벤트 속성을 쓴다

attachEvent(eventProperty, eventListener);
detachEvent(eventProperty, eventListener);

 

window.attachEvent('onload',function () {
	// load 이벤트 연결
});

인터넷 익스플로러의 이벤트 모델이므로 인터넷 익스플로러에서만 실행됨

 

window.onload = function () {
  var header = document.getElementById('my-header');

  // 인터넷 익스플로러의 경우 실행
  if (header.attachEvent) {
    var handler = function () {
      window.event.srcElement.style.color = 'red';
      window.event.srcElement.detachEvent('onclick', handler);
    };
    header.attachEvent('onclick', handler);
  }
};

이런게 있구나 정도로 알고있으면 됨!