편집
가 나는의 EventListener 인터페이스와 IE8을 모방 코드 조각을 썼다도 일반 개체에 대한 호출입니다 :이 에뮬레이션을하여 addEventListener 또는 방법입니다
https://github.com/antcolag/iEventListener/blob/master/iEventListener.js
OLD 답변 attachEvent를 지원하지 않는 브라우저에서
희망 하시겠습니까?
(function (w,d) { //
var
nc = "", nu = "", nr = "", t,
a = "addEventListener",
n = a in w,
c = (nc = "Event")+(n?(nc+= "", "Listener") : (nc+="Listener","")),
u = n?(nu = "attach", "add"):(nu = "add","attach"),
r = n?(nr = "detach","remove"):(nr = "remove","detach")
/*
* the evtf function, when invoked, return "attach" or "detach" "Event" functions if we are on a new browser, otherwise add "add" or "remove" "EventListener"
*/
function evtf(whoe){return function(evnt,func,capt){return this[whoe]((n?((t = evnt.split("on"))[1] || t[0]) : ("on"+evnt)),func, (!n && capt? (whoe.indexOf("detach") < 0 ? this.setCapture() : this.removeCapture()) : capt ))}}
w[nu + nc] = Element.prototype[nu + nc] = document[nu + nc] = evtf(u+c) // (add | attach)Event[Listener]
w[nr + nc] = Element.prototype[nr + nc] = document[nr + nc] = evtf(r+c) // (remove | detach)Event[Listener]
})(window, document)
브라우저가 DOM 객체에 대한 프로토 타입 상속 체계를 구현하는지 여부는 W3C [EventTarget 인터페이스] (http://www.w3.org/TR/DOM-Level-2-Events/events)를 지원하는지 여부와 관련이 없습니다. .html # Events-EventTarget-addEventListener). if (element.addEventListener) {/ * supported * /} else {/ * not supported * /}'는 모든 브라우저에서 유효하며 구현과 독립적입니다. – RobG