//兼容浏览器阻止事件冒泡,阻止浏览器默认动作,兼容IE和其他浏览器
function cancelClick(e){
if (window.event){
window.event.cancelBubble = true;
window.event.returnValue = false;
}
if (e && e.stopPropagation && e.preventDefault){
e.stopPropagation();
e.preventDefault();
}
}
var fn = function(e){alert("dd");EventUtil.unbind(document.getElementById("div1"), "click", fn);cancelClick(e)}
window.onload = function(){
EventUtil.bind(document.getElementById("div1"), "click", fn);
EventUtil.bind(document.getElementById("div2"), "click", fn);
}
var EventUtil = new Object();
EventUtil.bind = function( obj, eventType, fn){
if( obj.addEventListener){
obj.addEventListener(eventType, fn, false);
}else if( obj.attchEvent){
obj.attchEvent("on"+eventType, fn);
}else{
obj["on"+eventType] = fn;
}
}
EventUtil.unbind = function( obj, eventType, fn){
if( obj.removeEventListener){
obj.removeEventListener(eventType, fn, false);
}else if(obj.detachEvent){
obj.detachEvent("on"+eventType, fn);
obj["on"+eventType]=null;
}
}