Home > Article > Web Front-end > what are javascript events
Javascript events refer to things that happen on HTML elements. When JavaScript is used in an HTML page, JavaScript can trigger these events; its HTML events can be browser behaviors or user behaviors.
The operating environment of this article: windows7 system, javascript1.8.5&&html5 version, Dell G3 computer.
JavaScript Events
HTML events are things that happen to HTML elements.
When JavaScript is used in an HTML page, JavaScript can trigger these events.
HTML events
HTML events can be browser behaviors or user behaviors.
Usually, when an event occurs, you can do something about it.
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 代码">
In the following example, the onclick attribute is added to the button element (and the code is added):
Example
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>菜鸟教程(runoob.com)</title> </head> <body> <button onclick="getElementById('demo').innerHTML=Date()">现在的时间是?</button> <p id="demo"></p> </body> </html>
Effect:
In the above example, the JavaScript code will modify the content of the id="demo" element.
Recommended study: "javascript Advanced Tutorial"
The above is the detailed content of what are javascript events. For more information, please follow other related articles on the PHP Chinese website!