javascript - 从函数内部调用 $(document).ready() 是否安全?

标签 javascript jquery jquery-events

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

最佳答案

是的。

来自 jQuery ready 函数 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 );
}

关于javascript - 从函数内部调用 $(document).ready() 是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7142404/

相关文章:

javascript - Babel 7 没有正确转换内置子类

javascript - jQuery 事件委托(delegate)

javascript - 组合 Javascript block

javascript - 范围内的随机数,没有唯一性(宾果游戏)

javascript - angularjs ng-show div 在页面刷新后打开一秒钟

javascript - 在 Jquery 中循环更改文本

javascript - Jquery [object 对象] 而不是文本

javascript - 在 jQuery 中执行此过程的最有效方法是什么?

javascript - 使用 jQuery 的花式滑动表单

javascript - 避免在嵌套函数 jQuery 中使用 _this