从函数内部调用$(document).ready()是否安全? [英] Is it safe to call $(document).ready() from inside a function?

查看:69
本文介绍了从函数内部调用$(document).ready()是否安全?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我在函数中使用 $(document).ready()处理程序,它是否仍然保证其中的代码只会在文档中运行准备就绪,即使文件就绪事件过去发生得很好吗?

If I use the $(document).ready() handler from within a function, will it still guarantee that the code inside it will only be run if the document is ready, even if the document ready event has occurred well in the past?

推荐答案

是。

来自jQuery ready 函数来源

From the jQuery ready function source.

// Catch cases where $(document).ready() is called after the
// browser event has already occurred.
if ( document.readyState === "complete" ) {
    // Handle it asynchronously to allow scripts the opportunity to delay ready
    return setTimeout( jQuery.ready, 1 );
}

这篇关于从函数内部调用$(document).ready()是否安全?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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