需求:
当我们点击页面的最大或最小按钮时触发一个事件,具体实现的代码如下:
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;
}
}
};
EventUtil.addHandler(window, "resize", function () {
alert("Resized");
});
参考文章:https://www.w3cmm.com/javascript/resize.html;