【发布时间】:2012-03-18 15:04:40
【问题描述】:
我的主 HTML 文件动态加载内容;
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
</head>
<body>
Loading please wait
<script type="text/javascript">
$(document).ready(function(){
$('body').load("remotePage.html");
});
</script>
</body>
</html>
remotePage.html 是;
<html>
<head>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="script1.js"></script>
<script type="text/javascript" src="script2.js"></script>
<script type="text/javascript" src="script3.js"></script>
</head>
<body>
<script type="text/javascript">
function init(){
someFunctionThatDependsOnAllScripts(); //Fails because all scripts is not yet loaded
}
$(document).ready(init);
<script>
</body>
</html>
它失败是因为 script1.js 中的 ready 在 script1.js 加载之前被调用。 加载回调似乎没有帮助。
$(function(){
$('body').load("remotePage.html", function(){
init(); //doesn't work either
});
});
我如何知道用于加载 remotePage.html 所需资源的所有 ajax 操作何时完成? 如何解决?
谢谢
【问题讨论】:
-
你必须先包含 jQuery 库..
标签: jquery ajax jquery-load ready