At the beginning of this article, we will review the Javascript event mechanism. At the same time, it will be written from a minimum function to
At the beginning of this article, we will review the Javascript event mechanism. At the same time, it writes from the smallest function to the last powerful event module with complete functions. To facilitate the description, the response function, callback function, event Listener, and event handler are called event handler.
First, let's look at several ways to add events to the page:
- Directly write JS Code on HTML
Test: Nowamagic
Nowamagic
The HTML Element has many onXXX attributes. You only need to assign values to the JS Code. The string assigned to onXXX is used as the function body of the response function ). Probably this was written in the 1990s S. At that time, it was common to directly write JS Code on webpages. Maybe JavaScript was not very important at that time, but it was just used for verification or some fancy effects.
- Define a function and assign it to the onXXX attribute of the html element.