Search

10/02/2007

javascript idiom: attachevent+detachEvent vs. addEventListener+removeEventListener

if (target.addEventListener) target.addEventListener("mouseout", mouseout,
false); // DOM
else if (target.attachEvent) target.attachEvent("onmouseout", mouseout); // IE
else target.onmouseout = mouseout; // tradition

if (target.removeEventListener)
target.removeEventListener("mouseout", mouseout, false); // DOM
else if (target.detachEvent) target.detachEvent("onmouseout",mouseout); // IE
else target.onmouseout = null; // tradition

沒有留言: