gpt4 book ai didi

javascript - 在 标记之前放置脚本标记等同于 jQuery 的 document.ready 方法

转载 作者:数据小太阳 更新时间:2023-10-29 05:10:51 24 4
gpt4 key购买 nike

如果我们在关闭主体之前的脚本标签中调用javascript方法myMethod(),是否等同于在jQuery的document.ready函数中调用myMethod() ?如果不是,为什么?

最佳答案

来自 here :

Under the hood: $(document).ready() As you would expect from John Resig, jQuery’s method for determining when the DOM is ready uses an assortment of optimizations. For example, if a browser supports the DOMContentLoaded event (as many non-IE browsers do), then it will fire on that event. However, IE can’t safely fire until the document’s readyState reaches “complete”, which is typically later. If none of those optimizations are available, window.onload will trigger the event.

这些事件独立于 HTML 标记内的位置,因为即使在呈现时其他事件仍在进行 </body> .

关于javascript - 在 </body> 标记之前放置脚本标记等同于 jQuery 的 document.ready 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10173149/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com