前言:加载图片失败显示默认图
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<title>Document</title>
<script src="jquery-3.1.1.min.js"></script>
<script>
function nofind() {
var img = event.srcElement;
img.src = "404.png";// 百度图片的地址
img.onerror = null;// 控制不要一直跳动
}
</script>
</head>
<body>
<div class="box"></div>
<script>
let shtml='';
for(var i=0,len=3;i<len;i++){
// shtml+='<p>'
// +i+'<img src="1.png" onerror="nofind()"/>'
// +'</p>';
shtml+=`<p>
`+i+`<img src="1.png" onerror="nofind()"/>
</p>`;
}
$('.box').html(shtml);
</script>
</body>
</html>
追加:无数据显示默认图片
$('.nc_stylecentermess').html('<div style="text-align: center;padding: 30px;"><img src="/dsfa/res/dsf_styles/themes/img/nodata.png"/></div>')