function evnt(event) {
var evn = event,
eventDoc,//当前节点的顶层的 document 对象
doc,//document.documentElement
body,
button = evn.button;//鼠标按键值
evn.target = evn.target || evn.srcElement;
// Calculate pageX/Y if missing and clientX/Y available
if (evn.pageX == null && evn.clientX != null) {
eventDoc = evn.target.ownerDocument || document;//返回当前节点的顶层的 document 对象
doc = eventDoc.documentElement || eventDoc.body;
evn.pageX = evn.clientX + (doc.scrollLeft) - (doc.clientLeft);
evn.pageY = evn.clientY + (doc.scrollTop) - (doc.clientTop);
}
if (!evn.preventDefault) {
evn.preventDefault = function () {
this.returnValue = false;//取消发生事件源元素的默认动作
}
}
if (!evn.stopPropagation) {
evn.stopPropagation = function () {
this.cancelBubble = true;//ie冒泡行为
}
}
if (evn.which == null && (evn.charCode != null || evn.keyCode != null)) {
evn.which = evn.charCode != null ? evn.charCode : evn.keyCode;
}
// Add which for click: 1 === left; 2 === middle; 3 === right
// Note: button is not normalized, so don't use it
if (!evn.which && button !== undefined) {
evn.which = (button & 1 ? 1 : (button & 2 ? 3 : (button & 4 ? 2 : 0)));
}
return evn
};
兼容event函数
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- 1、将 event(e) 作为函数的参数,其中这个 event 代表的是“事件对象”,并且 event 拥有属性和...
- JavaScript — event介绍以及兼容处理 1.事件流 浏览器发展到第四代时(IE4及 Netscape...