zoukankan      html  css  js  c++  java
  • 跨浏览器实现自定义事件处理

    /**跨浏览器实现自定义事件处理
    *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");
    }
  • 相关阅读:
    jquery autocomplete
    hibernate 数据缓存
    Python变量类型
    Python基础语法
    Python环境搭建
    Python简介
    python下载地址
    第十、十一章,软件测试和软件演化
    第九章,软件实现
    第八章,面向对象设计
  • 原文地址:https://www.cnblogs.com/Mygirl/p/2045697.html
Copyright © 2011-2022 走看看