Home  >  Article  >  Web Front-end  >  What is an event in javascript

What is an event in javascript

藏色散人
藏色散人Original
2021-11-15 11:57:392538browse

The behaviors that can be detected in JavaScript are events, and through JavaScript code, HTML allows you to add event handlers to HTML elements.

What is an event in javascript

The operating environment of this article: windows7 system, javascript version 1.8.5, DELL G3 computer

What is an event in javascript?

JavaScript Events

HTML events are “things” that happen on HTML elements.

When JavaScript is used in an HTML page, JavaScript can "cope" with these events.

HTML Events

HTML events can be something the browser or the user does.

Here are some examples of HTML events:

HTML 网页完成加载
HTML 输入字段被修改
HTML 按钮被点击

Usually, when an event occurs, the user will want to do something.

JavaScript allows you to execute code when an event is detected.

HTML allows you to add event handlers to HTML elements through JavaScript code.

Use single quotes:

<element event=&#39;一些 JavaScript&#39;>

Use double quotes:

<element event="一些 JavaScript">

In the following example, the onclick attribute (and code) is added to the bb9345e55eb71822850ff156dfde57c8 element:

Example

<button onclick=&#39;document.getElementById("demo").innerHTML=Date()&#39;>现在的时间是?</button>

In the above example, the JavaScript code changes the content of the element with id="demo".

Recommended study: "javascript basic tutorial"

The above is the detailed content of What is an event in javascript. 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