Home >Web Front-end >JS Tutorial >JavaScript study notes (16) js events_basic knowledge

JavaScript study notes (16) js events_basic knowledge

WBOY
WBOYOriginal
2016-05-16 18:35:34961browse

Review
The event object contains three aspects of information...Look back at the previous article!

The properties and methods in the event object are mainly mouse and keyboard information.

1. Get the event type

Event object attribute type

2. Get the key code

Event object attribute keyCode: Enter is 13, space is 32, the back key is 8

3. Detect whether the Shift, Alt, Ctrl key

event object attributes are pressed: shiftKey, altKey, ctrlKey

4. Get the customer End coordinates

Event object properties clientX and clientY

5. Get screen coordinates

Event object properties screenX and screenY

Type of event
According to The things that trigger events and the objects in which events occur can be divided into several types of events in the browser:

1. Mouse events

Each mouse event Values ​​will be filled in for the attributes of the following event objects:

1. Coordinate attributes (such as clientX and client, etc.)

2. Type attribute

3.Targer (DOM) Or serElement (IE) attribute (target object attribute)

4.shiftKey, ctrlKey, altKey and metaKey (DOM) attributes

5.button attribute (only in mouse event)

(oEvent.target || oEvent.srcElement).id When the logical character or operator acts on two objects, if the first object is not empty, the first object will be returned, otherwise the second object will be returned, which is represented here Is the ID of the element that caused the event.

2. Keyboard events

Keydown --- Occurs when a key is pressed on the keyboard. Keep pressing a key and it will trigger continuously.

Keypress --- Occurs when a key is pressed and a character is generated (that is, regardless of keys like Shit ctrl alt.) It will continue to occur as long as the key is pressed.

Keyup --- Occurs when the pressed key is released

1. Event attributes

For each keyboard event, the following event attributes will be filled in:

keyCode attribute (the ASC code value of the key)

charCode attribute (DOM only)

target (DOM) and srcElement (IE) attributes

shiftKey, ctrlKey, altKey and metaKey (DOM) attributes

2. Sequence

When the user presses a character key once, events will occur in the following order:

(1), keydown;

(2), keypress;

(3), keyup;

If the user presses a non-character key (such as shift) , events will occur in the following order:

(1), keydown;

(2), keyup;

3. HTML events

Onload, unload, resize, scroll and other events.

4. Mutation events

Add and delete nodes in the subtree of a document or element element. Currently, no mainstream browser has implemented it.

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