用javascript 怎么判断图片是否加载完成呢

用javascript 怎么判断图片是否加载完成呢?

function loadImage(url){
var o= new Image();
o.src = url;
if(o.complete){

window.alert(‘图片加载完成:’+url);

}else{
o.onload = function(){

window.alert(‘图片加载完成:’+url);

};
o.onerror = function(){

window.alert(‘图片加载失败:’+url);

};
}
}

如果我要先把这一个图片加载完,之后才显示怎么处理呢.

function showImage(url){ var o = document.createElement('img'); o.src = url; document.body.appendChild(o); } function loadImage(url){ var o= new Image(); o.src = url; if(o.complete){ showImage(url); }else{ o.onload = function(){ showImage(url); }; o.onerror = function(){ window.alert('图片加载失败:'+url); }; } }

18 thoughts on “用javascript 怎么判断图片是否加载完成呢

  1. Pingback: T shirts, mugs, t-shirt

  2. Pingback: Darknet

  3. Pingback: togel hongkong

  4. Pingback: 바카라사이트

  5. Pingback: axiolabs clenbuterol

  6. Pingback: 메이저바카라

  7. Pingback: 메이저바카라

  8. Pingback: cash bitcoin

  9. Pingback: keluaran hk

  10. Pingback: m88 bi chan

  11. Pingback: Buy Psychedelics Online

  12. Pingback: CBD Capsules

  13. Pingback: french bulldog puppies for sale near me in usa canada uk australia europe cheap

  14. Pingback: http://63.250.38.81

  15. Pingback: Bitcoin Evolution Review

  16. Pingback: Buy DMT Vape Cartridges Online for sale near me in USA Canada UK Australia overnight delivery cheap

  17. Pingback: 토토사이트

  18. Pingback: 안전공원

Leave a Reply