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
I have been quite free recently. I have been doin...
Table of contents Target Thought Analysis Code la...
We know that there are two ways to receive incomi...
Table of contents Configuration nfs server (nfs.s...
Preface The effect problems used in personal actu...
I installed a Linux Ubuntu system on my computer....
1. What is a transaction? A database transaction ...
Table of contents Preface Centering inline elemen...
The Docker package is already included in the def...
Table of contents variable Use meaningful and pro...
Preface 1. The tools used in this article can be ...
Problem [root@zh ~]# [root@zh ~]# [root@zh ~]# yu...
Preface The requirement implemented in this artic...
Preface Managing routing is an essential feature ...
JavaScript now releases a new version every year,...