跨浏览器实现自定义事件处理
时间:2011-05-13 来源:Mygirl
/**跨浏览器实现自定义事件处理
*author:Mygirl
**/
window.DEvent = {
addListener:function(obj,target,act){
if(obj.attachEvent)
obj.attachEvent("on" + target , act);
if(obj.addEventListener)
obj.addEventListener(target , act , false);
}
removeListener:function(obj,target,act){
if(obj.detachEvent)
obj.detachEvent("on"+target,act);
if(obj.removeEventListener)
obj.removeEventListener(target,act,false);
}
}
Object.prototype.eventHandler = function(handler){
var b = this ;
b = b;
return function(c){
if(!c){
c = window.event ;
}
if(c&&!c.target){
c.target = c.srcElement;
}
b[handler](c);
}
}
调用方法如下:
function test(){
var container = document.getElementById("div1");
this.container.onmouseMove = this.eventHandler("onMouseMoveMouse");CEvent.addListener(this.container, "mousemove", this.eventHandler("onmapmousemove"));
}
onMouseMoveMouse.js
Zx.prototype.onmapmousemove = function(evt) {
/*var cpointtmp = new ZxPoint(this.container.offsetLeft + evt.clientX - this.mapDiv.offsetLeft, this.container.offsetTop + evt.clientY - this.mapDiv.offsetTop);
Theodolite$setPoint(cpointtmp);*/
alert("test");
}
相关阅读 更多 +