Add an event to the element in Firefox and pass the parameter-addeventlistener attachevent-PASS Parameters to event-function.

Source: Internet
Author: User
But you can get information of the object where the event occured. e. g. you can do stuff dependent on the "ID" of an object, or you can set any additional flags within the object and do stuff dependent on these flags.

Here we have the code for attaching the events:

 
If (window. addeventlistener) {// Mozilla, Netscape, firefoxobject. addeventlistener ('mouseover', testevent, false); object. addeventlistener ('click', testevent, false); object. myflag = "test"; object. mydata = "123";} else {// ieobject. attachevent ('onmouseover', testevent); object. attachevent ('onclick', testevent); object. myflag = "test"; object. mydata = "123 ";}

The function "testevent" contains all code to access the "ID", "name" etc. And all own flags:

Function testevent (EVT) {var e_out; var ie_var = "srcelement"; var pai_var = "target"; var prop_var = "myflag"; // "target" for Mozilla, Netscape, firefox et al .; "srcelement" for ieevt [comment _var]? E_out = EVT [cmd_var] [prop_var]: e_out = EVT [ie_var] [prop_var]; alert (e_out); prop_var = "mydata"; EVT [cmd_var]? E_out = EVT [pai_var] [prop_var]: e_out = EVT [ie_var] [prop_var]; alert (e_out );}

Conclusion: If you set appropriate flags When attaching an event to an object, you have the possiblity to do actions dependent on these flag when the actual event occurs.
Therefore it is not necessary to pass parameters directly when attaching the event, since those parameters either do not change anyway, or if the parameters are dynamically created, those dynamic parameters can be read out in the function "testevent ".

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.