jQuery插件不适用于Ajaxed内容 [英] Jquery plugins not working on ajaxed content
问题描述
我有一些正在使用jquery ajax加载的内容.内容中附加了jquery插件(例如模式框).
I have some content that I am loading using jquery ajax. The content has jquery plugins attached (example a modal box).
我的问题是,因为ajax的内容不是原始dom的一部分,所以没有对其应用插件.
My problem is that because the ajaxed content isn't part of the original dom it hasn't had the plugins applied to it.
我如何将插件应用于ajax的内容???有什么办法可以重新初始化插件吗???
How do I apply the plugins to ajaxed content??? Is there someway I can reinitialize i the plugins???
推荐答案
您可以像这样在ajax成功函数中调用插件:
You can call the plugin in the ajax success function like this:
$.ajax({
//Stuff..
success: function(data) {
$(".selector", data).myPlugin();
}
});
这仅在返回的html中调用匹配选择器上的插件,因此它将不再在页面的其余部分上运行.
This calls the plugin on the matching selector only in the html that was returned, so it won't run on the rest of the page again.
这篇关于jQuery插件不适用于Ajaxed内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!