在修改DOM后window.onload等效? [英] window.onload equivalent after modifying the DOM?

查看:104
本文介绍了在修改DOM后window.onload等效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当页面首次加载时,我们可以使用 window.onload 来确保在我们执行某些操作之前已经加载了所有资源。

When a page first loads we can use window.onload to make sure that all resources have loaded before we do something.

我的问题是,如果我们修改DOM(例如,根据ajax请求插入一些html),是否有任何事件将在文档再次处于加载状态时触发? strong>(例如,当插入的HTML包含多个图像时)。

My question is, if we modify the DOM (e.g. inserting some html based on an ajax request), is there any event that will fire when the document is in the 'loaded' state again? (e.g. when the html inserted contains multiple images).

(使用jQuery的解决方案会很好)。

(Solution with jQuery would be fine).

推荐答案

简短的答案:
NO。

The short answer: NO.

长的答案:
如果你知道你正在寻找你可以使用突变观察员( https://developer.mozilla.org/ EN-US /文档/ DOM / MutationObserver )。它只支持新的浏览器,在某些版本的chrome中,它与封闭使用时会有内存泄漏。

The long answer: if you know what you are looking for you can use mutation observers (https://developer.mozilla.org/en-US/docs/DOM/MutationObserver). it is only support in new browser, and in some version of chrome it has memory leaks when used with closures.

BTW,
document.ready不告诉你是否所有(或任何..)资源被加载。它只告诉你,dom已经准备就绪(即加载功能,只会在所有资源之后才能触发)(以及使用javascript不被请求的任何资源)被下载)。

BTW, document.ready doesn't tell you if all (or any..) of the resources were loaded. it only tell you well, that the dom is ready (that is the load function, which will only fire after all resources (well, any resources that isn't requested using a javascript) were downloaded).

这篇关于在修改DOM后window.onload等效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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