文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>跨浏览器实现自定义事件处理

跨浏览器实现自定义事件处理

时间: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");
}
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载