我有这个图片标签:
<img id="viewerofinstore" src="{{filteredArray[imageIndex]}}"
onError="this.style.visibility = 'hidden'"
onload="this.style.visibility = 'visible'" width="297px" height="297px" />
图像的src
每秒钟都会随着其他图像发生变化,但也有一些图像磨损并出现未知图像的情况。
我添加了 "onError="this.style.visibility = 'hidden'"
但有时我可以在隐藏之前看到未知图像一秒钟。
我想在显示之前捕获未知图像并放置默认图像或隐藏图像。
最佳答案
您可以将 img 默认隐藏,只有在正确加载时才可见。
<img id="viewerofinstore" src="{{filteredArray[imageIndex]}}" style="visibility:hidden"
onload="this.style.visibility = 'visible'" width="297px" height="297px" />
关于javascript - 在 <img> 标签上捕获未知图片并设置默认图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15458255/