【发布时间】:2011-05-19 23:32:17
【问题描述】:
我只想在成功加载图像时显示图像(某些路径给出 404)。 有以下代码,效果很好。
<script>
$(document).ready(function() {
$(".complex-image").load(function(){
$(this).show();
});
});
</script>
现在,其中一个页面显示了谷歌地图,其中设置:
onload = initMap
onunload = GUnload
在 IE8 和 Chrome 中的此页面上,即使可用,图像也不显示。但在 Firefox 4 中显示良好。我的站点中包含图像+地图的示例页面是 this
我也尝试过相反的方法:加载错误时隐藏图像。使用以下代码:
<script>
$(document).ready(function() {
$(".complex-image").ready(function(){
$(this).hide();
});
});
</script>
这不会在 IE8 上隐藏地图和不包含地图的页面上的图像。
当定义了正文 onload 时,在成功加载时显示图像的跨浏览器方式是什么?
编辑:使用 Elzo 的解决方案,即使在从缓存中读取图像时也会触发 img.load(),使用这个: jQuery callback on image load (even when the image is cached)
【问题讨论】:
标签: javascript jquery cross-browser