Event bindings and common events in JS and jquery

Source: Internet
Author: User

An ordinary event is a direct event registration of an element, which then triggers

The event binding is to register the event on the element

The difference is that ordinary events can not be repeated to add multiple events, and if added will overwrite, only one event will be triggered (the last registered)

Event binding is the ability to repeatedly bind multiple events, and all can trigger

And in jquery It's a bit different, and jquery itself allows you to add multiple trigger functions through ordinary events

    function Foo1 () {        alert (' Trigger click 1 ');    }    function Foo2 () {        alert (' Trigger click 2 ');    }    Will trigger two function pop-up trigger click 1 Trigger Click 2    $ (". AcK1"). On (' click ', foo1);    $ (". AcK1"). On (' click ', Foo2);        $ (". Ack2"). Click (foo1);    $ (". Ack2"). Click (foo2);    Will trigger two function pop-up trigger click 1 Trigger Click 2

Event binding in jquery refers to event firings on dynamically created element bindings, not just multiple events for an element

Note the dynamic binding of events to an element, which is generally required to be bound by the parent class element, before the child class (the element just added) can be triggered

    $ (document). On (' click ', '. AcK1 ', foo1);    $ (". AcK1"). Click (function () {        var ele=$ (this). Clone ();        $ (this). After (Ele); Post-cloned elements can still trigger the Foo1 event function    });    $ (". Ack2"). Click (foo2);    $ (". Ack2"). Click (function () {        var ele=$ (this). Clone ();        $ (this). After (Ele); Unable to trigger Foo2 event function    });

Event bindings and common events in JS and 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.