你怎么知道文件是否准备好了 [英] how do you know if document is ready

查看:72
本文介绍了你怎么知道文件是否准备好了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成HTML块的JavaScript。此脚本有时在运行时调用,有时在加载文档之前调用。我想要一个能够判断文档是否准备就绪的脚本。如果是,则生成HTML,否则,添加document.ready()函数。什么是jQuery知道文档是否已被加载的最佳方式?

I have a JavaScript that generates HTML blocks. This script is sometimes called somewhere in run time, and sometimes before document is loaded. I want a script that is able to tell if document is ready. If so, generate the HTML, otherwise, add a document.ready() function. What is jQuery's best way to know if document has been loaded?

推荐答案

始终将该HTML生成代码包装在$中是安全的(文件)。就绪()。如果文档已经准备就绪,则会立即执行新注册的$(document).ready()回调。

It's safe to always wrap that HTML generation code in $(document).ready(). If the document is already ready, a newly registered $(document).ready() callback will execute immediately.

这篇关于你怎么知道文件是否准备好了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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