Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the common events in javascript

Shulou Source: shulou.com Published: 2022-06-01 13:17:03 10月05日 Update

This article mainly introduces the relevant knowledge of "what are the events commonly used in javascript". The editor shows you the operation process through actual cases, and the operation method is simple, fast and practical. I hope this article "what are the events commonly used in javascript" can help you solve the problem.

The common events in javascript are: 1, click events (onclick and ondblclick); 2, focus events (onblur and onfocus); 3, load events (onload); 4, mouse events; 5, keyboard events; 6, select and change events; 7, form events.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

Events in JS:

Concept: some components trigger the execution of some code after some actions have been performed.

Event: some actions. Click, double click, the keyboard is pressed, the mouse is moved

Event source: component. Such as: button text input box.

Listener: code.

Register listeners: combine events, event sources, and listeners. When an event occurs on the event source, the execution of a listener code is triggered.

1. Common events

1) Click event:

Onclick: click event

Ondblclick: double-click event

2) focus event

Onblur: lose focus

Onfocus: the element gets focus.

3) load event:

Onload: a page or an image is loaded.

4) Mouse event:

The onmousedown mouse button is pressed.

The onmouseup mouse button is released.

The onmousemove mouse is moved.

Onmouseover mouse over an element.

Move the onmouseout mouse away from an element.

5) Keyboard events:

Onkeydown one of the keyboard keys is pressed.

One of the keyboard keys in onkeyup has been released.

One of the onkeypress keyboard keys is pressed and released.

6) Select and change events

The contents of the onchange domain have been changed.

The onselect text is selected.

7) form event:

The onsubmit confirmation button is clicked.

The onreset reset button is clicked.

2. Registration of events

3.1. What is the registration (binding) of events?

In fact, it is to tell the browser what action code to perform after the event response, called event registration or event binding.

3.2. Two ways to register events (static registration events and dynamic registration events)

Static registration of events: the event attribute of the html tag is directly assigned to the code after the event response, which is called static registration.

Function sayHello () {alert ("hello js!");}

Tags: Event code object mouse dynamic keyboard function common button key label focus monitor element enter key property listener knowledge static content Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple vpn Linux Docker Shulou Technology