Customized javascript event processing (discussion)

Source: Internet
Author: User

Customized javascript event processing (discussion)
I am a little embarrassed to write the articles about event listening in the garden. But think about my questions starting with a private production. Concepts related to events 1. the string of an event of the event type includes the conventional event types such as form and window events. DOM event types HTML5 event types such as drag, drop touch screen, and mobile device event types such as touchmove2. event target Window/Document/Element /XMLHttpRequest /... 3. the event object is a familiar event4. the event propagation browser determines which object triggers the event processing program. The event object is in the bubble stage and is in the stage and captured. phase registration event handler 1. set the property of the event target to the required event handler function, such as dom1.onclick = function (){/*.... */}; 2. set the HTML Tag attribute to an event handler, for example, <p onclick = 'alert ('My little apple'); '/> but the actual javascript engine performs the following processing: it is equivalent to prefixing the scope, indicating that it does not have a deep understanding of. Copy the code function (event) {with (document) {with (this. form | {}) {with (this) {/* here is the encoding */}. The final suggestion for copying the code is: We recommend separating JavaScript code from html, in this way, it is in line with the respective responsibilities of html and javascript. when a handler is registered through properties, such as e. onclick = function () {/**/} this indicates the event target object 2. for attachEvent (), this indicates the window object, so you can refer to the following code to copy the code function addEvent (target, type, handler) {if (target. addEventListener) target. addEventListener (type, handler, false); else target. attachEvent ("on" + Type, function (event) {return handler. call (target, event) ;}}copy the return value of the Code event handler. If the return value is false, the default browser operations can be prevented, such as link jump, if return false, the call sequence of Jump events can be blocked. 1. the handler registered by setting the object property or HTML property is always preferentially called. 2. the handler registered by addEventListener () is called in the order they are registered. 3. the processing program registered by attachEvent () may call events in any order. Here we have to say that the DOM2-level event requires that the event contains three phases 1. event capture Phase 2. in target stage 3. the event bubble phase here borrow http://www.cnblogs.com/yexiaochai/p/3567597.html's example and film it to find the copy Code

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.