Is it necessary to set onload function before setting src for an image object?

后端 未结 5 1548
别那么骄傲
别那么骄傲 2020-12-01 14:42

I was told it is necessary to set the onload function before setting src for an image object. I\'ve searched in SO for this.

I found this c

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-01 15:14

    The browser will start downloading the image asychronously as soon as you assign a src, so there is the possibility the download could complete before you attach the onload event handler and never fire the code to add the image to the DOM.

提交回复
热议问题