Get the App
SLTechnology News&Howtos  ›  Development  › 

What parts does the javascript event consist of

Shulou Source: shulou.com Published: 2022-06-02 07:29:42 09月21日 Update

This article mainly introduces "javascript event consists of what parts", in daily operation, I believe many people in javascript event consists of what parts of the question there are doubts, small editor consulted all kinds of information, sorted out simple and easy to use operation methods, hope to answer "javascript event consists of what parts" doubts helpful! Next, please follow the small series to learn together!

In javascript, an event consists of an event source, an event type, and an event handler. Event Source refers to the element that triggers the event, Event Type refers to how the event is triggered, and Event Handler refers to the code (in the form of a function) that is executed after the event is triggered.

Operating environment of this tutorial: Windows 7 system, Javascript version 1.8.5, Dell G3 computer.

What is an Event?

Events are actions that can be detected by JavaScript and are a "trigger-response" mechanism. These behaviors refer to specific actions such as page loading, mouse click/double click, mouse pointer sliding in a certain area, etc., which play a very important role in realizing the interactive effect of the page.

Event consists of event source, event type and event handler, which is also called "event three elements."

three elements of event

Event Source: The element that triggers (is) the event

Event type: how the event is triggered (e.g. mouse click or keyboard click)

Event handler: code to execute after an event is triggered (functional form)

The above three elements can be simply understood as "who triggered the event,""what event triggered," and "what to do after triggering the event."

Example: Changing the color of a div by clicking a button

Event Source: Button Element

Event type: mouse click

Event handler: test(eventObj)

mouse events //js How to access the style attribute of an element and make style modifications function test(eventObj) { How do you know if button1 is pressed or button2 is pressed? //window.alert(eventObj.value); if(eventObj.value == "black") { //get div1 var div1 = document.getElementById("div1"); div1.style.background = "black"; } else if(eventObj.value == "red") { var div1 = document.getElementById("div1"); div1.style.background = "red"; } } div1

At this point, the study of "what parts of javascript events are composed of" is over, hoping to solve everyone's doubts. Theory and practice can better match to help everyone learn, go and try it! If you want to continue learning more relevant knowledge, please continue to pay attention to the website, Xiaobian will continue to strive to bring more practical articles for everyone!

Tags: Event part program type mouse processing element learning element three code function form button way more behavior page help practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Huawei Shulou Tech Info Shulou Information vpn