Events in jsWhat is an event? Events are responses to interactions between computer input devices and pages, which we call events. Event Type
Common events
Event Registration What is event registration (binding)?
Basic steps for dynamic registration: 1. Get the tag object Static and dynamic registration examples onload loading completion eventStatic binding:<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Static Registration</title> <script type="text/javascript"> // onload event method function onloadFun() { alert('Statically register onload event, all codes'); } </script> </head> <!--Statically register the onload event. The onload event is an event that is automatically triggered after the browser parses the page. The attribute of the body tag is registered through this attribute--> <body content="onloadFun();"> </body> </html> Dynamic Binding:Fixed writing method, through window.onload(){} method, calling the method in curly braces <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Dynamic Registration</title> <script type="text/javascript"> // Dynamic registration of onload event. It is a fixed writing method window.onload = function () { alert("Dynamically registered onload event"); } </script> </head> <body> </body> </html> onclick click eventFor example, we can better understand the difference between the two definitions from this example. onclick static binding event<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript"> function onclickFun() { alert("Statically register onclick event"); } </script> </head> <body> <!--Statically register the onClick event through the button's onclick attribute--> <button onclick="onclickFun();">Button 1</button> </body> </html> onclick dynamic binding event<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript"> window.onload = function () { //getElementById gets the tag object through the id attribute var btnObj = document.getElementById("btn01"); // 2 through the tag object. Event name = function(){} btnObj.onclick = function () { alert("Dynamically registered onclick event"); } } </script> </head> <body> <button id="btn01">Button 2</button> </body> </html> The above is the detailed content of the detailed explanation of the concept of JavaScript events (distinguishing between static registration and dynamic registration). For more information about JavaScript events, please pay attention to other related articles on 123WORDPRESS.COM! You may also be interested in:
|
<<: 27 Linux document editing commands worth collecting
>>: MySQL Optimization: Cache Optimization
Many concepts in UI design may seem similar in wo...
There are too many articles about xhtml+css websi...
In Dockerfile, run, cmd, and entrypoint can all b...
A large part of data management is searching, and...
Swarm Cluster Management Introduction Docker Swar...
Why should we read the log? For example, if the c...
Yesterday I wanted to use a:visited to change the...
Find the containerID of tomcat and enter the toma...
I want to achieve a situation where the width of ...
MySQL 8.0.22 installation and configuration metho...
This article uses an example to illustrate the pa...
Table of contents 1. What is a cursor? 2. How to ...
The method of obtaining the position of the point...
<br />For an article on a content page, if t...
This article example shares the specific code of ...