var image = new Image(); image.src = "xxx.jpg"; image.onload = function() { document.getElementById("img").src = image.src; } var image = new Image(); image.onload = function() { document.getElementById("img").src = image.src; }
obj.find(".proBox > .image > a > img").each(function() { //遍历图片,检查是否需要加载图片 if ($(this).attr("status") == "unload" || $(this).attr("status") == "") { //未加载的图片 var realSrc = $(this).attr("real"); var target = this; //建立一个可以给image.onload函数调用的对象 var image = new Image(); image.onload = function complete() { //加载完成 $(target).attr("status", "loaded"); //加载完成 } function check() { //ie7下显示bug的修复 if (image.complete) { complete(); } else { setTimeout(function() { check(); }, 500); //每隔0.5秒检查一次 } } if (document.all) { check(); } image.src = realSrc; $(target).attr("status", "loading"); //加载中 } });
dobj.find(".proBox > .image > a > img").each(function() { //遍历图片,检查是否需要加载图片 if ($(this).attr("status") == "unload" || $(this).attr("status") == "") { //未加载的图片 var realSrc = $(this).attr("real"); var target = this; //建立一个可以给image.onload函数调用的对象 var image = new Image(); image.onload = function complete() { //加载完成 $(target).attr("status", "loaded"); //加载完成 } /*function check(){//ie7下显示bug的修复 if(image.complete){ complete(); }else{ setTimeout(function(){check();},500);//每隔0.5秒检查一次 } } if(document.all){check();}*/ setTimeout(function() { image.src = realSrc; }, 300); $(target).attr("status", "loading"); //加载中 } });
查看更多关于关于img的onload事件兼容ie下的bug问题的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did25083