The example in this article describes how JavaScript implements adding multiple event handlers for a specified object. Share to everyone for your reference. Specifically as follows:
If you want to handle multiple things while the object clicks, you can use the following code
/* Start of the Multihandle object...*/function Multihandle (owner) {var my_handlers = new Array ();
var My_owner = owner;
This.append = function (handler) {my_handlers[my_handlers.length] = handler;
} This.fire = function (evt) {var i;
for (i = 0; i < my_handlers.length i++) {my_owner.tempspace = my_handlers[i];
My_owner.tempspace (EVT); }}/* End of the Multihandle object*//* Start of the "Object add event handler script * * */*this bit goes where you ' d Normally write ... object.onmouseup = [Event Handler] ... where [event handler] is ' an existing function ... tha ' is T handles an event, or even a ... 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];}
The
wants this article to help you with your JavaScript programming.