Window. event. srcElement: Tips for getting event source object_javascript

Source: Internet
Author: User
Window. event. srcElement: Get the code of the event source object. You can refer to the Code sent by the script home before. It is compatible with multiple views.

<Html> <body> <p> one advantage is that I want the body (or other elements) some object response events do not need to be written one by one on the outer layer and then check the event. srcElement. whether the tagName or other attributes are what you want to determine whether to respond to the event. but it seems like event. srcElement does not work in ff </p> <p> for example </p> <input value = "input"> span </p> <p> p </p>/ p> <p> event object refers to the event object Currently triggered, 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> <textarea rows = "10" cols = "90"> <script syntax Ange = "javascript"> document. onclick = myfunc; function myfunc () {alert (window. event. srcElement. tagName);} script </textarea> <script Ange = "javascript"> document. onclick = myfunc; function myfunc () {alert (window. event. srcElement. tagName);} script </p> <p>. Void (0) is a function that does nothing. </P> </body>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

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.