jQuery的 - 的document.ready不点火时加载的内容与AJAX [英] jQuery - document.ready not firing when content loaded with AJAX

查看:187
本文介绍了jQuery的 - 的document.ready不点火时加载的内容与AJAX的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的自定义Tab键模块,加载标签与AJAX请求(通过 $(ELEM).load())。在那个装有AJAX每一页我有一些JavaScript。第一次加载页面(通过URL,而不是AJAX的直接输入),JavaScript的火灾达完美。当我通过AJAX的标签导航离开该页面,从页面的JavaScript不加载了。

I have a simple custom tabbing module, that loads tabs with an AJAX request (via $(elem).load()). On each page that is loaded with AJAX I have some JavaScript. The first time the page loads (via direct input of URL, not AJAX), the javascript fires up perfectly. When I navigate away from the page via the AJAX tabs, the javascripts from the pages aren't loading anymore.

有没有什么办法可以强制他们执行?

Is there any way I can force them to execute?

(即不点火被放置在一个 $(文件)。准备中的JavaScript()功能是否有帮助)

(The javascript that is not firing is placed in a $(document).ready() function if that helps)

推荐答案

您需要使用 负载的回调() 功能:

You need to use callback of load() function:

$(elem).load('source.html', function() { 
    // here you need to perofrm something what you need
    ActionOnDocumentReady();
});

您可以把你的 $(文件)。就绪所有行动统一到一些功能(如 ActionOnDocumentReady() ),并把它在 负载() 回调。

You can put all your actions in $(document).ready into some function (ex ActionOnDocumentReady()) and call it on load() callback.

这篇关于jQuery的 - 的document.ready不点火时加载的内容与AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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