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
Blank's blog: http://www.planabc.net/ The use...
Code Sample Add a line of code in the head tag: XM...
This article example shares the specific code of ...
Preface: The "Getting Started with MySQL&quo...
Table of contents Uninstall and install samba Cre...
This article shares the specific code of JavaScri...
Method 1: float:right In addition, floating will ...
The latest tutorial for installing MySQL 8.0.25 o...
This article shares the specific code of Bootstra...
login.html part: <!DOCTYPE html> <html l...
Problem description: The user has a requirement t...
First and foremost, I am a web designer. To be mor...
This article shares the installation steps and us...
1. <div></div> and <span></s...
Table of contents 1. Component 2. keep-alive 2.1 ...