Home > Web Front-end > JS Tutorial > body text

what are javascript events

藏色散人
Release: 2023-01-05 16:14:30
Original
2655 people have browsed it

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.

what are javascript events

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=&#39;JavaScript 代码&#39;>
Copy after login

Double quotes:

<some-HTML-element some-event="JavaScript 代码">
Copy after login

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(&#39;demo&#39;).innerHTML=Date()">现在的时间是?</button>
<p id="demo"></p>

</body>
</html>
Copy after login

Effect:

what are javascript events

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template