Home >Web Front-end >Front-end Q&A >Can javascript respond to events?
Javascript can respond to events, because JavaScript can be set to be executed when an event occurs; events are things that happen on html elements. When JavaScript is used on an html page, JavaScript can These events are triggered, such as when the page is loaded or when the user clicks on an HTML element.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
Can javascript respond to events?
Can JavaScript be set to when an event occurs? It will be executed, such as when the page is loaded or when the user clicks on an HTML element.
HTML events are things that happen to HTML elements.
When JavaScript is used in an HTML page, JavaScript can trigger these events.
HTML events can be browser behaviors or user behaviors.
The following are examples of HTML events:
HTML page completes loading
HTML input field changes
HTML Button Clicked
Normally, when an event occurs, you can do something.
JavaScript can execute some code when the event is triggered.
Event attributes can be added to HTML elements and JavaScript code can be used to add HTML elements.
Single quotes:
<some-HTML-element some-event='JavaScript 代码'>
Double quotes:
<some-HTML-element some-event="JavaScript 代码">
The example is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>123</title> </head> <body> <button onclick="getElementById('demo').innerHTML=Date()">现在的时间是?</button> <p id="demo"></p> </body> </html>
Output result:
【Related recommendations: javascript video tutorial, web front-end】
The above is the detailed content of Can javascript respond to events?. For more information, please follow other related articles on the PHP Chinese website!