In web development, it is normal to obtain the width and height of the image. The width and height of the image cannot be obtained before the image is loaded. The width and height of the image itself can be obtained only after the loading is completed, for example:
OK? There is nothing wrong with this code, but there is a bug in IE. It is fine when I open it for the first time, but it is a tragedy the second time I use this method. IE does not respond, even if I refresh it. The same goes for pages. Because IE caches images, the image loaded for the second time is not uploaded from the server, but loaded from the buffer.
Write the onload method first, and then specify the URL of this image, and it will be normal. Therefore, it is not that IE does not trigger the onload event, but because the buffer is loaded so fast that the onload event has already been triggered before img.onload is run. That's OK.