Home  >  Article  >  Web Front-end  >  js pay attention to the analysis of onerror event of img picture_javascript skills

js pay attention to the analysis of onerror event of img picture_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:12:411452browse

After analysis, it was found that there is code similar to the following in the webpage:

pic
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:

Copy code The code is as follows:

< script type="text/javascript">
function nofind(){
var img=event.srcElement;
img.src="../../. ./sys/common/image/fileoperation/icon/default.gif";
img.onerror=null; Control not to keep beating
}
//–>

${file.name }
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn