页面完全加载后如何执行功能? [英] How to execute a function when page has fully loaded?

查看:90
本文介绍了页面完全加载后如何执行功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在页面完全加载时执行一些JavaScript代码。这包括像图像这样的东西。

I need to execute some JavaScript code when the page has fully loaded. This includes things like images.

我知道你可以检查DOM是否准备就绪,但我不知道这是否与页面完全加载时相同。

I know you can check if the DOM is ready, but I don’t know if this is the same as when the page is fully loaded.

推荐答案

这叫做onload。在DOM准备就绪之前,它已经出现了,并且实际上已经创建了DOM就绪,因为onload等待图像的确切原因。

That's called onload. It came waaaaay before DOM ready was around, and DOM ready was actually created for the exact reason that onload waited on images.

window.onload = function () { alert("It's loaded!") }

这篇关于页面完全加载后如何执行功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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