Home >Web Front-end >JS Tutorial >Detailed analysis of jQuery.event events compatible with various browsers_jquery
Before the introduction, let’s introduce a method of jQuery, jQuery.event.fix(event || window.event); This method converts the browser’s event object into jQuery.event; if your event is bound through the jQuery method , no need to convert!
JQuery encapsulates common attributes of events while following W3C specifications, so that event processing can run normally in all major browsers without the need for browser type judgment.
1.event.type attribute
This method is used to get the type of time
2.event.preventDefault() method
The function of this method is to prevent the default event behavior. The preventDefault() method in JavaScript that complies with the W3C specification is invalid in IE browser. jQuery encapsulates it to make it compatible with various browsers.
3.event.stopPropagation() method
This method is to prevent the bubbling of events. The stopPropagation() method in JavaScript that complies with the W3C specification is invalid in IE browser. jQuery encapsulates it to make it compatible with various browsers.
4.event.target attribute
The function of the event.target attribute is to obtain the element that triggers the event. After jQuery encapsulates it, it avoids the differences between different standards of W3C, IE and safari browsers.
6.event.pageX/event.pageY attribute
The function of this method is to obtain the x-coordinate and y-coordinate of the cursor relative to the page. If jQuery is not used, the event/event.y method is used in IE browser, and the event.pageX/event.pageY method is used in Firefox browser. If there are scroll bars on the page, add the width and height of the scroll bars. In IE browser, the default 2px border should also be subtracted.
8.event.metaKey property
According to different browsers’ different interpretations of the
9.event.originalEvent property.
The function of this method is to point to the original event object.