我试图使用jQuery来确定图像是否已正确加载.
以下工作正常(并返回true或false作为图像的状态),但似乎只在IE中工作,在FireFox中,它似乎总是返回true- 即使状态实际上是不完整的:
var image = $("img#myImage");
alert(image[0].complete);
Run Code Online (Sandbox Code Playgroud)
image.complete在JavaScript或jQuery中Firefox的等价物是什么?
我只是写
document.createElement("img").complete;//To check whether image is loaded or not
Run Code Online (Sandbox Code Playgroud)
在Firefox中,它返回true.在IE中,它返回false
要么
在html页面中,只需创建一个图像:
<!-- IMG tag with no SRC attribute. -->
<img id="noSrcImg" />
Run Code Online (Sandbox Code Playgroud)
并在js中检查完整的属性值:
var img = document.getElementById("noSrcImg");
img.complete
Run Code Online (Sandbox Code Playgroud)
对于FF,为true,对于IE为false
任何人都可以解释为什么这种不一致的行为?
有没有其他更好的方法来检查DOM中是否加载了图像?
我尝试使用readyState属性,但它不适用于IE11.