//// 监听事件 监听使用各种浏览器
// var p1 = document.getElementById("p1");
//// 监听事件
// eventUtil.addEvent(p1,"click",p1Fun);
//// 移除事件
// eventUtil.deleteEvent(p1,"click",p1Fun);
//
// var p1Fun = function(){
// alert("p1")
// }
// var eventUtil = {
addEvent:function(element,type,handle){
if(element.addEventListener){
element.addEventListener(type,handle,false);
}else if(element.attachEvent){
var newType = "on" + type;
element.attachEvent(newType,handle,false)
}else{
var newType = "on" + type;
element[newType] = handle;
}
}
,
deleteEvent:function(element,type,handle){
if(element.removeEventListener){
element.removeEventListener(type,handle,false);
}else if(element.detachEvent){
var newType = "on" + type;
element.detachEvent(newType,handle,false)
}else{
var newType = "on" + type;
element[newType] = null;
}
}
};
对于不同浏览器的监听事件