加载中的文档不起作用,但加载时的窗口起作用 [英] document on load does not work but window on load does
问题描述
我正试图让我的脚本仅在加载了整个页面(包括图片)后才能运行.
I'm trying to get my script to run only after my entire page has loaded included the pictures.
所以我一直在使用这段代码.
So I have been using this code.
$(document).on('load', function() { $('#loading').hide(); });
这是行不通的,因为它永远不会激活.但是,当我使用窗口而不是文档时,它可以工作,但不是我所需要的.在激活之前,我需要加载包括图片在内的所有内容.
This does not work, since it never activates. However, when I use window instead of document then it works, but its not what I need. I need everything including pictures to be loaded before activating.
我很困惑为什么这行不通.
I'm very confused why this does not work.
编辑
这不是基本的加载文档,而是文档就绪问题.即使加载了此代码,我的图片也没有完全加载.
THis is not a basic onload document, vs document ready question. My pictures are are not fully loaded even when this code loads.
$(window).on('load', function(){ $('#loading').hide(); });
推荐答案
没有document
load
事件. load
事件发生在window
对象上.
There is no document
load
event. The load
event occurs on the window
object.
document
上有一个DOMContentReady
事件,它与窗口load
事件的发生时间不同.
There is a DOMContentReady
event on the document
which occurs at a different time than the window load
event.
由于要加载所有资源,因此需要如下窗口load
事件:
Since you want all resources to be loaded, what you want the window load
event like this:
$(window).on('load', function() {
$('#loading').hide();
});
这篇关于加载中的文档不起作用,但加载时的窗口起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!