事件操做對象:對象
var EventUrl = {事件
//添加事件element
addHandler: function (element, type, handler) {
if (element.addEventListener) {
element.addEventListener(type, handler, false);
}else if (element.attachEvent) { //IE
element.attachEvent("on" + type, handler, false);
} else {
element["on" + type] = handler;
}
},rem
//移除對象
removeHandler: function (element, type, handler) {
if (element.removeEventListener) {
element.removeEventListener(type, handler, false);
} else if (element.detachEvent) { //IE
element.detachEvent("on" + type, handler, false);
} else {
element["on" + type] = null;
}
},get
//獲取事件對象
getEvent: function (event) {
return event ? event : window.event;
},io
//獲取目標對象
getTarget: function (event) {
return event.target || event.srcElement;
},event
//取消默認事件
preventDefault: function (event) {
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue;
}
},function
//中止冒泡List
stopPropagation: function (event) {
if (event.stopPropagation) {
event.stopPropagation();
} else {top
event.cancelBubble = true; } } };