JavaScript learning notes (16) js events

Source: Internet
Author: User

Review
The event object contains three pieces of information!

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

1. Get the Event Type

Event object property type

2. Obtain the key code

Event object property keyCode: Press enter to 13, space to 32, and back to 8

3. Check Shift, Alt, and Ctrl keys

Whether the event object property is pressed: shiftKey, altKey, ctrlKey

4. Obtain client coordinates

Event object attributes clientX and clientY

5. Get screen coordinates

Event object attributes screenX and screenY

Event Type
Based on the events that trigger the event and the objects that occur, events that occur in the browser can be divided into several types:

I. mouse events

Each mouse event is filled with values for the properties of the following event objects:

1. Coordinate attributes (such as clientX and client)

2. Type attributes

3. Targer (DOM) or serElement (IE) attributes (target object attributes)

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

5. button attribute (only in the mouse event)

(OEvent.tar get | oEvent. srcElement ). when the id logical operator acts on two objects, the first object is not empty, and the first object is returned. Otherwise, the second object is returned, which indicates the ID of the element that caused the event.

Ii. Keyboard Events

Keydown --- occurs when a key is pressed on the keyboard. If you keep pressing a key, it will be triggered continuously.

Keypress --- press a key and generate a character (that is, a key like Shit ctrl alt .) When you press the key all the time, it will continue to happen.

Keyup --- release the pressed Button

1. Event attributes

For each keyboard event, the following event attributes are entered:

KeyCode attribute (ASC code value of the key position)

CharCode attribute (DOM only)

Target (DOM) and srcElement (IE) attributes

ShiftKey, ctrlKey, altKey, and metaKey (DOM) attributes

2. Order

When you press a button for a certain character, an event occurs in the following order:

(1) keydown;

(2) keypress;

(3) keyup;

If you press a non-character button (such as shift) at a time, the event occurs in the following order:

(1) keydown;

(2) keyup;

Iii. HTML events

Onload, unload, resize, scroll and other events.

Iv. Mutation events

The addition and deletion nodes of the Child tree of the document or element are not implemented by any mainstream browsers.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.