JS Events Object (event)

Source: Internet
Author: User

#事件对象 (Event)

Div.onclick = function (event) {
Console.log (event);
Let E = event| | window.event; Resolve compatibility
}

# #事件对象的属性

1) Target object: E.target (Gets the element that triggered the event)

2) This points to the bound element

# # #鼠标相关的属性
1) coordinates relative to the browser (document display area): ClientX, ClientY

2) relative to the page coordinates: PageX, pagey; if there is a scrollbar, the hidden coordinates are calculated

3) relative to the screen coordinates: ScreenX, ScreenY

4) coordinates relative to event Source: OffsetY, OffsetX
# # #键盘相关的属性

1) KeyCode: Key value code, character code, enter key value code is 13

# #事件对象的方法
1) Block Event flow

E.stoppropagation ();
2) The default behavior of blocking events (for example: A tag comes with the jump function)

A.onclick = function (e) {
E.preventdefault ();
}
Ie:

1) Block Event flow

E.cancelbubble = true;
2) default behavior for blocking events

E.returnvalue = false;

# #事件委托

1) Vernacular version: The things to be done by the class entrusted to the ancestors of the elements to do

2) Official version: Event delegation, the actual use of event bubbling principle, the specific sub-node operation, delegated to the gendarme range of ancestor node to deal with

JS Events Object (event)

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.