Window. event. srcelement-get the event source object

Source: Internet
Author: User
Code
< Html >
< Body >
< P > One advantage is that I want some objects in the body (or other elements) to respond to events without writing them one by one.
You only need to write one on the outer layer and check whether event. srcelement. tagname or other attributes are what you want to determine whether to respond to the event. However, it seems that event. srcelement does not work in ff. </ P >
< P > For example </ P >
< P >
< Input Value = "Input" >
< BR >
< Span > Span </ Span > </ P >
< Div > Div </ Div >

< P > Event object refers to the currently triggered event object, and window. event. srcelement refers to the object that triggers the event. For example, you set document. onclick = myfunc; at this time, all the page Click events are handed over to myfunc for processing. In the myfunc function, you can write vsrc = Window. event. srcelement, know where the user clicked, and perform corresponding processing.
Add the following section to an HTML file: </ P >
< P >
< Textarea Rows = "10" Cols = "90" >
< Script Languange = "JavaScript" >
Document. onclick = Myfunc;
Function Myfunc ()
{
Alert (window. event. srcelement. tagname );
}
</ Script >  
</ Textarea >
< Script Languange = "JavaScript" >
Document. onclick = Myfunc;
Function Myfunc ()
{
Alert (window. event. srcelement. tagname );
}
</ Script >
</ P >
< P > Try it. < A Href = # > Void (0) is a function that does nothing. </ A >
</ P >
</ Body >

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.