标签:
var EventUtil = { addHandler: function(element, type, handler){ if (element.addEventListener){ element.addEventListener(type, handler, false); } else if (element.attachEvent){ element.attachEvent("on" + type, handler); } else { element["on" + type] = handler; } }, removeHandler: function(element, type, handler){ if (element.removeEventListener){ element.removeEventListener(type, handler, false); } else if (element.detachEvent){ element.detachEvent("on" + type, handler); } else { element["on" + type] = null; } } };
var btn = document.getElementById("myBtn"); var handler = function(){
alert("Clicked"); };
EventUtil.addHandler(btn, "click", handler); //
EventUtil.removeHandler(btn, "click", handler);
标签:
原文地址:http://www.cnblogs.com/xingweb/p/4239643.html