开发者

Can onload event fire right after setting image src attribute?

开发者 https://www.devze.com 2023-04-07 06:21 出处:网络
What console log can开发者_运维百科 be after this code will be executed? var img = new Image; img.onload = function() { console.log(\'B\'); };

What console log can开发者_运维百科 be after this code will be executed?

var img = new Image;
img.onload = function() { console.log('B'); };
img.src = 'image.jpg';
for (var i=0;i<100000;i++) {
  console.log('A');
}

I know, that most likely it will be A...AB. But can it be A...B...A or BA...A? For example, if image.jpg is very small file and connection is very fast.


It can be any of them. You don't know how long it takes to load the image. The image could even be cached, minimizing the loading time.

0

精彩评论

暂无评论...
验证码 换一张
取 消