Events in JQuery and JQuery events

Source: Internet
Author: User

Events in JQuery and JQuery events
JQuery event first

 

1. Event binding in JQuery

In fact, the standard event binding in JQuery is written as follows: (as follows)

$ ("# Btn"). bind ("click", function (){});

But every time I Write this, it's too much trouble. How can I Write less and Do more?

Therefore, we are used to abbreviated it.

$ ("# Btn"). click (function () {}) makes it much easier

2. Combine event hover (enterfn, leavefn)

Call the enterfn method when you place the cursor over the element,

Call the leavefn method when the mouse leaves the element.

It is equivalent to the combination of mouseover and mouseout events in javascript.

Event bubbling
 

1. Description

Event bubbling: JQuery uses the event bubbling mechanism like JavaScript.

, Window. event. cancelBubble = true

2. Get

If you want to capture event-related information, add the parameter e to the response's anonymous function. e is the event object.

Call the stopPropagation () method of the event object to terminate the bubble.

E. stopPropagation ();

After the bubble is terminated, the program will not run on the parent element of the event source.

3. Event bubble chart

Block events
 

Block default behavior: some elements have default behavior. For example, after a hyperlink is clicked, the new link is switched and the submit button is used to submit a form by default. To prevent default behavior, you only need to call the preventDefault () of the event object () method and window. event. returnValue = false has the same effect.

$ ("A"). click (function (e ){

Alert ("All hyperlinks are temporarily prohibited from clicking ");

E. preventDefault ();

});

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.