JQuery processing interactive content
I noticed that in jquery appended text won't be processed by jquery functions. For example, you append a code containing dropdown-list and you have a function that invokes on changing its value. This function works on existing code only, not on appended one.
And the correct answer is:
Instead of using:
$('#purchase-table select').change(function() {
});
Use:
$('#purchase-table select').live('change', function() {
});
You need it to be able to process ajax-appended content by your jquery functions. Have a nice day.
开发者_JAVA百科Thanks to everyone helped.
You can use JQuery .live()
Append new content:
$('body').append('<div class="clickme">Another target</div>');
Add handler to it:
$('.clickme').live('click', function() {
// Live handler called.
});
Then clicks on the new element will also trigger the handler.
The easiest way to handle events on interactive content is the jQuery.live
method.
http://api.jquery.com/live/
Description: Attach a handler to the event for all elements which match the current selector, now and in the future.
精彩评论