To the button click event bound invalid

1. Analysis: Button after Ajax requests, successful request to the data, using JQuery dynamically generated. Ajax requests are asynchronous refresh mechanism, such as the above code is not executed. Therefore, when this type to bind the click event of a button, the button has not been created, then, click the event naturally not bound to the button.

2. Solution:

    ① when the button is created on the binding event.

    ② using JQuery's .live () method: to match all the elements attach an event handler, even if this element is added after coming too effective. But beginning in version 1.7 of JQuery is deleted, you should add an event handler to use .on (). Users using the old version, should be preferred .delegate () instead .live ().

    ③ using JQuery newly added in 1.7 .on () to add an event handler.

3. .on () the specific use can refer to the official document: https://www.runoob.com/manual/jquery/

Guess you like

Origin www.cnblogs.com/lveyHang/p/11788015.html