onLoad 到底何时发生
我特别关心 DOM 选定元素的 onload 事件。出于示例目的,假设我的 DOM 中有一个图像。
正如我认为我所理解的那样,当图像绘制到屏幕上时,应该触发该图像的 onload 事件,但最近我得到的数据表明并非如此。所以我的问题如下:
按照以下事件的顺序,图像的 onload 事件何时触发?
- 检查包含图像的 HTML
- 对图像发出请求 收到图像的
- 第一个字节 收到
- 最后一个字节
- 浏览器检查 HTTP 响应的标头
- 图像被绘制到屏幕上
我特别关心 Firefox,但我也会感兴趣这如何影响 Internet Explorer(特别是 IE8)和 Chrome
I am specifically concerned with the onload event for selected elements of the DOM. For the purpose of example assume there is an image in my DOM.
As I thought I understood it, the onload event for this image should fire when the image is drawn to the screen, but recently I've been given data to suggest otherwise. So my question is as follows:
When, in the order of the following events, does the onload event for an image fire?
- HTML containing the image is examined
- Request is made for the image
- First Byte is received for the image
- Last Byte is received
- Browser examines the header of the HTTP response
- Image is drawn to the screen
I am specifically concerned with Firefox, but I would also be interested in how this affects Internet Explorer (specifically IE8) and Chrome
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
加载事件发生在屏幕上绘制图像之后。
演示: http://jsfiddle.net/e5hvr/
(警报会阻止浏览器线程,因此如果尚未绘制图像,则在警报仍打开时您将无法看到它。)
The load event occurs after the image has been drawn on the screen.
Demo: http://jsfiddle.net/e5hvr/
(The alert blocks the browser thread, so if the image hadn't been drawn already, you wouldn't be able to see it while the alert is still open.)
根据 jQuery 文档
因此,为了回答你的问题,我会在你列出的所有事件之后说。
Per the jQuery docs
So, to answer your question, I would say after all of the events you listed.
我会说除了 6 之外的所有。当然,你的事件顺序是错误的;标题位于数据之前。
I would say all but 6. And your events are in the wrong order, of course; the headers come before the data.