且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在JavaScript中隐藏破碎的图像?

更新时间:2022-10-15 23:34:26

您可以使用onerror处理程序。在内联表格中,它看起来像这样:

 < img src =someimage.jpgonerror =this.style 。显示=无; /&GT; 


I have my image inside an if statement:

if (item.image)
   historyHtml += '<a href=' + item.image + ' class="image" target="_blank"><img src="' + item.image +'" width="111px"/></a>';

You can use the onerror handler. In the inline form, it looks like this:

<img src="someimage.jpg" onerror="this.style.display='none';" />