Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如今,人们向图像添加预加载器是很常见的。即使未加载所有图像,它也有助于呈现网站。我的问题是,当调用预加载器时,它不会检查任何缓存的图像。它总是从服务器加载图像。在调用图像预加载器之前,您是否有任何想法检查图像是否有损坏?我的预加载器功能就在下面。
$(function(){ $("#container").preloader(); });
它加载主 div 内的所有图像。
您想知道图像是否加载正确?
$('#image').onload(function(){alert('Fires when image is loaded');});
或者
if(document.getElementById('image').complete){alert('Image is loaded');}
这就是您如何检查图像是否已加载。