Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
正如这里所建议的那样,http://www.sitepoint.com/jquery-vs-raw-javascript-3-events-ajax/正在页面底部在结束正文标记之前加载脚本,这是一种非常可靠的了解方式DOM 准备好了吗?
总结以上评论:
在页面底部加载脚本并不是了解 DOM 已准备就绪的可靠方法。正如@cgatian 所建议的那样,使用onloadordocument.ready事件对此更好。
onload
document.ready
在结束标记之前加载脚本的典型好处</body>是确保在执行脚本之前完成 HTML/页面呈现,从而最大限度地减少向用户显示内容所需的时间:这意味着用户“看到”页面尽快,但不一定在页面完成加载/执行所有脚本时。
</body>