Home > Article > Web Front-end > What is an event in javascript
The behaviors that can be detected in JavaScript are events, and through JavaScript code, HTML allows you to add event handlers to HTML elements.
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='一些 JavaScript'>
Use double quotes:
<element event="一些 JavaScript">
In the following example, the onclick attribute (and code) is added to the bb9345e55eb71822850ff156dfde57c8 element:
Example
<button onclick='document.getElementById("demo").innerHTML=Date()'>现在的时间是?</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!