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

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...