javascript 事件框架
javascript事件模型框架-eventutil.js
var EventUtil = new Object;
EventUtil.formatEvent = function (oEvent) {
//isIE和isWin引用到一个js文件,判断浏览器和操作系统类型
if (isIE && isWin) {
oEvent.charCode = (oEvent.type == "keypress") ? oEvent.keyCode : 0;
//IE只支持冒泡,不支持捕获
oEvent.eventPhase = 2;
oEvent.isChar = (oEvent.charCode > 0);
oEvent.pageX = oEvent.clientX + document.body.scrollLeft;
oEvent.pageY = oEvent.clientY + document.body.scrollTop;
//阻止事件的默认行为
oEvent.preventDefault = function () {
this.returnValue = false;
};
//将toElement,fromElement转化为标准的relatedTarget
if (oEvent.type == "mouseout") {
oEvent.relatedTarget = oEvent.toElement;
} else if (oEvent.type == "mouseover") {
oEvent.relatedTarget = oEvent.fromElement;
}
//取消冒泡
oEvent.stopPropagation = function () {
this.cancelBubble = true;
};
oEvent.target = oEvent.srcElement;
//添加事件发生时间属性,IE没有
oEvent.time = (new Date).getTime();
}
return oEvent;
};
EventUtil.getEvent = function() {
if (window.event) {
//格式化IE的事件
return this.formatEvent(window.event);
} else {
return EventUtil.getEvent.caller.arguments[0];
}
};

浙公网安备 33010602011771号