本文实例讲述了JavaScript实现为指定对象添加多个事件处理程序的方法。分享给大家供大家参考。具体如下:
如果你希望对象点击的时候同时处理多个事情,可以使用下面的代码
/This bit goes where you'd normally write...
... object.onmouseup = [event handler]...
... where [event handler] is an existing function ...
... that handles an event,or even an
... anonymous function./
if(typeof(MultiHandle) != "undefined"){
var mup_handler = object.mh_onmouseup;
if(!mup_handler){
mup_handler = new MultiHandle(object);
object.mh_onmouseup = mup_handler;
object.onmouseup = function(evt){
this.mh_onmouseup.fire(evt);
};
}
mup_handler.append([event handler]);
}else{
object.onmouseup = [event handler];
}
... object.onmouseup = [event handler]...
... where [event handler] is an existing function ...
... that handles an event,or even an
... anonymous function./
if(typeof(MultiHandle) != "undefined"){
var mup_handler = object.mh_onmouseup;
if(!mup_handler){
mup_handler = new MultiHandle(object);
object.mh_onmouseup = mup_handler;
object.onmouseup = function(evt){
this.mh_onmouseup.fire(evt);
};
}
mup_handler.append([event handler]);
}else{
object.onmouseup = [event handler];
}
希望本文所述对大家的javascript程序设计有所帮助。
原文链接:https://www.f2er.com/js/54716.html