Home >Web Front-end >Front-end Q&A >Can javascript respond to events?

Can javascript respond to events?

WBOY
WBOYOriginal
2022-06-17 10:53:011737browse

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.

Can javascript respond to events?

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

Can javascript respond to events?

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

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

Output result:

Can javascript respond to events?

【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!

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