请原谅我,我是新手。
我有一个 .html 文件集合,根据选择的文件,我将其加载到页面上的 div 中,有点像 iframe。我可以让这一切正常工作,但我的问题是窗口加载事件。我可以让 onload 在主页上工作,但是加载到主页上 div 的页面上包含的 onload 事件不起作用,无论我将其写入 .html 文件还是从外部文件调用它。 $(document).ready 有效,但我试图确保 javascript 在其他所有内容之后加载。
基本上我不知道如何让窗口加载在加载到 div 的页面上工作。
任何帮助将不胜感激。
编辑:这会将外部页面之一加载到主页面中:
$('div#socket').load('pages/' + thisTab + '.html');
其中 thisTab 是其中一个文件的名称,也是所选选项卡的名称。
这样的内容将位于已加载页面之一的底部:
<script type="text/javascript">
$(document).ready(function(){
alert('1');
});
$(window).load(function(){
alert('2');
});
$(window).bind("load", function() {
alert('3');
});
</script>
我只收到“1”的提醒。
最佳答案
如果我理解正确的话,您正在寻找一个在将某些内容加载到主页(使用ajax)后执行某些操作的选项。您可以使用ajax加载方法的回调功能。
$("#DivInsideMainPage").load("remotepage.html",function(){
alert("This will execute only after loading the partial content")
//Execute the fancy code you want here
});
关于javascript - 无法让 $(window).load() 在加载到 div 的页面上工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13794292/