JQuery event binding function one: The Bound event processing function is executed only once. jqueryone

Source: Internet
Author: User

JQuery event binding function one: The Bound event processing function is executed only once. jqueryone

JQuery binds event handlers in two ways (method 1 and method 2). Method 3 is rarely used.

Method 1:

$ ("# Button"). click (function (){});


This method is very simple, and is also the most common practice of coding. The original events in HTML, such as onclick, onmouseover, and onkeypress. JQuery encapsulates the names in a simple way. For example, onclick corresponds to JQuery's click, and onmouseover corresponds to JQuery's mouseover. You can view JQuery's API and find that the event name in JQuery is basically removed from the on in the original HTML event name.

 

Method 2:

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

For details about bind/unbind, refer to this article.

 

Method 3:

$ ("# Button1"). one ("click", function (){});

Method 1 and Method 2: as long as the event binding is not canceled, the event processing function will be executed when a specific event occurs. In method 3, the event processing function can be executed only once at most. That is to say, event binding in method 3 is one-time, and once used, it will be useless.

 

The three event registration methods are not much different. If the event processing function is not required, you can use unbind to cancel the event.

 

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.