Jquery has not been used for a while, and today we have encountered this problem. At that time, we knew that livejquery could solve the problem. But I don't like loading another one for this purpose. I used to manually bind the event handler when I added it. However, this function has been added to the new jquery version. We don't need to worry about it anymore.
Reference: http://api.jquery.com/live/
Previously, we defined events. For example, we wrote a click event for the element definition as follows:
$ ('Input'). click (function (){
// Process the code
});
Copy code
Or
$ ('. Clickme'). bind ('click', function (){
// Bound handler called.
});
Copy code
However, this can only be used to define events for the loaded elements. elements that are inserted later must be bound separately. Even if you use jquery's clone function, it cannot replicate events (so far, I still have no idea why it is defined like this, whether it cannot be copied or deliberately processed, to prevent some exceptions, it is still necessary to analyze the jquery source code ).
Now, you can easily use live,
$ ('. Clickme '). live ('click', function () {// Live handler called .}); in this way, even if you insert the elements dynamically behind it, it will be bound to an event, $ ('body '). append ('<div class = "clickme"> Another target </div> ');
From if one day...