如果我在函数中使用 $(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/