Home > Web Front-end > JS Tutorial > Two good ways to obtain event sources in javascript event functions_javascript skills

Two good ways to obtain event sources in javascript event functions_javascript skills

WBOY
Release: 2016-05-16 16:55:22
Original
1105 people have browsed it

In JavaScript event response, in many cases we need to obtain the event source object to change its properties, such as changing the src attribute of img. There are two ways to obtain the event source in the event response function:

The first way:

Directly pass it in as a parameter. For example,

Copy code The code is as follows:

text




Second:

Use the hidden event object directly. The event object has a srcElement attribute, which can be accessed directly
Copy code The code is as follows:

< ;div id="myid" onclick="show();">text



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template