我正在尝试使用 jQuery 来确定图像是否已正确加载。
以下工作正常(并返回 true
或 false
作为图像的状态)但似乎只在 IE 中工作,在 FireFox 中,它似乎始终返回 true
- 即使状态实际上是不完整的:
var image = $("img#myImage");
alert(image[0].complete);
JavaScript 或 jQuery 中 image.complete
的 Firefox 等价物是什么?
最佳答案
除了 complete
之外,您还可以尝试检查 img
元素的其中一个维度:
function isImageLoaded() {
var theImage = $('#myImage');
if (!theImage.get(0).complete) {
return false;
}
else if (theImage.height() === 0) {
return false;
}
return true;
}
卸载的 img
或具有无效 src
属性的 img
应该有 .height()
和 .width()
在 Firefox 中等于 0
。在 Chrome 和 Opera 中,这两种方法似乎都无法正常工作。在那些浏览器中,theImage.height()
在我的测试中总是返回正值。
关于javascript - FireFox 中的 `complete` 属性存在哪些解决方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1268557/