Anu*_*tna 5 html javascript image internet-explorer-11
我只是写
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.
请尝试加载
还要确保在分配 src 之前定义事件处理程序 - 在非常快的网络上,如果没有首先定义,src 可能会在事件处理程序之前加载
var im = document.createElement("img");
im.onload=function() { alert(this.src+' loaded')} // assign before src
im.onerror=function() { alert(this.src+' failed')} // if necessary
im.src="someimage.jpg";
Run Code Online (Sandbox Code Playgroud)