About jquery using bind dynamic BIND event Invalid handling

Source: Internet
Author: User

Recently in the development of the page, when doing page effects, you need to give a dynamically loaded button to an event


Then use $ (obj) without hesitation. bind (); To bind the event.

But there is a problem with this:

Bind can actually bind events, but that's relative to fixed HTML tags.


When the content of the page is dynamically loaded, there is a bug in the Bind event, only one bind at a time, which is useless when you trigger the event for the second time.


For example:

I give the <a> tag a click, and the <a> tag includes content that is read from the background data and then loaded dynamically. When I use bind to bind the Click event, the first click clicks can trigger a successful

But the second click, the click event is invalid ...


A later study found thatjquery also had a way to bind events: Delegate (); Use the following:

$ (". Sentnum-box"). Delegate (". A-add-ordergoods", "click", Function () {        //JS Data code});

This enables dynamic data-bound events to be implemented and will never expire




About jquery using bind dynamic BIND event Invalid handling

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.