My method at the time was to manually bind the event handler function when adding it. However, the new version of jquery has added this feature. We no longer need to worry about this.
Reference: http://api.jquery.com/live/
We used to define events, such as defining a click event for an element like this:
$('input').click(function () {
//Processing code
}) ;
or
$ ('.clickme').bind('click', function() {
// Bound handler called.
});
But this can only be done for loaded Element definition events, those elements that are added later need to be bound separately. Even if you use jquery's clone function, it cannot copy the event (so far I don't know why it is defined like this, whether it cannot be copied or is handled this way deliberately to prevent certain exceptions, which remains to be analyzed) Take a look at the source code of jquery).
Now, you can do it easily using live,
$('.clickme').live('click', function() { // Live handler called. }); In this way, you can dynamically insert it later The element will also be bound to the event, $('body').append('
Another target
');
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn