Home >Web Front-end >JS Tutorial >js pay attention to the analysis of onerror event of img picture_javascript skills
After analysis, it was found that there is code similar to the following in the webpage:
Analysis: Pay special attention to onerror. When the picture does not exist, onerror will be triggered, and onerror specifies a NoPic.gif picture for img. That is to say, pic.gif will be displayed if the picture exists, and noPic.gif will be displayed if the picture does not exist. But here comes the problem. If noPic.gif does not exist, onerror will continue to be triggered, causing a loop, so an error occurs.
Note: If the image exists but the network is not smooth, onerror may also be triggered.
Solution:
First method: Remove the onerror code; or change the onerror code to something else; or ensure that the image in onerror is small enough and exists.
Second type: