//支持跨浏览器的添加事件。
var btn = document.getElementById("btn");
function showMes() {
alert("hello world!");
}
var eventUtil = {
addHander:function(element,type,hander) {
//判断是否是除IE以外的DOM2级操作
if (element.addEventListener) {
element.addEventListener(type,hander,false);
} else if(element.attachEvent){
element.attachEvent("on"+type,hander);
}else{
element["on"+type] = hander;
}
},
removeHander:function(element,type,hander) {
//判断是否是除IE以外的DOM2级操作
if (element.removeEventListener) {
element.removeEventListener(type,hander,false);
} else if(element.detachEvent){
element.detachEvent("on"+type,hander);
}else{
element["on"+type] = null;
}
},
getEvent:function(event) {
return event?event:window.event;
},
getType:function(event) {
return event.type;
},
getElement:function(event) {
return event.target||event.srcElement;
},
preventDefault:function(event) {
if (event.preventDefault) {
event.preventDefault();
} else{
event.returnValue=false;
}
},
stopPropagation:function(event) {
if (event.stopPropagation) {
event.stopPropagation();
} else{
event.cancleBubble = true;
}
}
}