jQuery插件不适用于Ajax加载的内容 [英] jQuery plugins not working for Ajax loaded content

查看:160
本文介绍了jQuery插件不适用于Ajax加载的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个恼人的问题,我使用bootstrap 2.3和一些jQuery插件表单样式和东西。

Hey guys I have an annoying problem, am using bootstrap 2.3 and some jQuery plugins for form styling and stuff.

当我加载ajax内容,更具体地选择元素... jQuery插件不捕获它们,并且不对其进行风格化。

When I load in ajax content, more specifically select elements ... the jQuery plugin doesn't capture them and doesn't style them as a result.

有什么办法可以将这些插件应用到Ajax加载内容,而不是必须加载这些插件再次每当我发出ajax请求?

is there any way that I can apply those plugins to Ajax loaded content other than having to load those plugins again whenever I make an ajax request?

推荐答案

像Kevin说的,你需要在加载新元素后初始化插件。一个简单的方法是注册一个处理程序,为所有的ajax请求调用。

Like Kevin said you need to initialize the plugin on the new elements after you load them. An easy way to do this globally is register a handler to be called for all ajax requests.

 $(document).ajaxComplete(function(event, xhr, settings) {
     $('.myForm').thePlugin();
 }

这篇关于jQuery插件不适用于Ajax加载的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆