About the events of jquery

Source: Internet
Author: User

One, event binding

The JQ event bindings before jq1.7 are implemented by the Bind method, as follows

$ (' selector '). Bind (' EventType ', data, CallBack);

Pairing method Unbind

jqury1.7 before a similar pre-bound live, it is implemented by bubbling way, as follows

$ (' selector '). Live (' EventType ', Data, callBack);

Pairing method die

The event agent in Jqury, as follows

$ (' selector '). Delegate (' Childdom ', Eventtype,data, callBack);

Pairing Method Ondelegate

1.7 After the on method, using the on method binding way is also similar

$ (' selector '). On (' EventType ', Selector,data, callBack);

Pairing method off

Difference:

The 1.bind method is used to bind events to selected elements and cannot bind elements that do not yet appear

The 2.live method is implemented by event bubbling, which can bind elements that are not currently present (pre-bound) and discard after 1.7

3.delegate dedicated to event broker

4.on integrates the above three methods (for 1.7 later)

Ii. Custom Events

Custom events in Jqury do not need to be declared, bind directly using bind or other above methods, as follows

$ (window). bind (' Love ', function () {//Bind custom event, window here can be any object

Alert (' Love ');

});

$ (window). Trigger ("Love");//Touch a custom event

Usage scenarios:

The main idea is to solve the basic events in the browser can not complete the requirements, generally used for component outward exposure events, to achieve decoupling.

About the events of jquery

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.