브라우저 간에 사용자 정의 이벤트 처리

6160 단어 브라우저

  
    
/* *
*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 " );
}

좋은 웹페이지 즐겨찾기