Check if an image is loaded (no errors) with jQuery

前端 未结 15 1559
挽巷
挽巷 2020-11-21 20:45

I\'m using JavaScript with the jQuery library to manipulate image thumbnails contained in a unordered list. When the image is loaded it does one thing, when an error occurs

15条回答
  •  时光取名叫无心
    2020-11-21 21:08

    Using this JavaScript code you can check image is successfully loaded or not.

    document.onready = function(e) {
            var imageobj = new Image();
            imageobj.src = document.getElementById('img-id').src;
            if(!imageobj.complete){ 
                alert(imageobj.src+"  -  Not Found");
            }
    }
    

    Try out this

提交回复
热议问题