JS批量检查当图片不存在时则显示默认图片的代码

<script type="text/javascript"> 
        var imgs = document.images; 
        for(var i = 0; i<imgs.length; i++){ 
            imgs[i].onerror = function(){ 
                this.src = "http://www.jb51.net/images/logo.gif"; 
            } 
        } 
</script>

或者:

<img src="" border="0" onerror="this.src='http://www.veryhuo.com/images/logo.gif'"/>

 

你可能感兴趣的:(js)