About toggle event Delegate processing, toggle event Delegate

Source: Internet
Author: User

About toggle event Delegate processing, toggle event Delegate

 

After an html page is loaded, events such as buttons that need to be dynamically loaded on the page are bound. We have two solutions:

1. Bind after reload

 

Ii. bind with Delegation

 

The toggle event cannot be directly bound. In this case, it can be converted to a click event, and a value is saved. Based on this value, it is determined that it has been clicked several times for processing, the code example is as follows:

 

$ ('# Sample _'). on ('click ','. openBtn ', function () {var toggled = $ (this ). data ('togged'); $ (this ). data ('togged ',! Toggled); if (! Toggled) {x1 () ;}else {x2 ();}});

 

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.