/*绑定事件与取消绑定*/
var handleHash ={};
var bind =(function(){
if(window.addEventListener){
return function(e1,type,fn,capture){
e1.addEventListener(type,function() {
fn();
handleHash[type]=handleHash[type] ||[];
handleHash[type].push(arguments.callee);
},capture);
};
}else if(window.attachEvent){
return function(e1,type,fn,capture) {
e1.attachEvent("on"+type,function(){
fn();
handleHash[type]=handleHash[type] ||[];
handleHash[type].push(arguments.callee);
})
}
}
})();
var unbind =(fuction(){
if(window.addEventListener){
return funtion(e1,type){
if(handleHash[type]){
var i=0,len = handleHash[type].length;
for(i;i<len;i+=1){
e1.removeEventListener(type,handleHash[type][i]);
}
};
};
}else if(window.attachEvent){
return function(e1,type){
if(handleHash[type]){
var i=0,len = handleHash[type].length;
for(i;i<len;i+=1){
e1.detachEvent("on"+type,handleHash[type][i]);
}
}
}
}
})();
网友评论