javascript – 将标记放在标记之前,等同于jQuery的document.ready方法

前端之家收集整理的这篇文章主要介绍了javascript – 将标记放在标记之前,等同于jQuery的document.ready方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果我们在关闭body之前的脚本标记调用 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>时,其他事件仍在进行中.

原文链接:https://www.f2er.com/jquery/150525.html

猜你在找的jQuery相关文章