JavaScript implements methods for adding multiple event handlers for a specified object _javascript tips

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.