Home  >  Article  >  Web Front-end  >  what are javascript events

what are javascript events

藏色散人
藏色散人Original
2021-05-11 14:38:252654browse

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;>

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

</body>
</html>

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!

Statement:
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