Home > Web Front-end > JS Tutorial > 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
Release: 2016-05-16 18:12:41
Original
1473 people have browsed it

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 }
Related labels:
img
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template