微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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>时,其他事件仍在进行中.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐