图片获取失败用默认图代替

2018-02-13  本文已影响0人  洱月

通过对图片大小的判断来处理

$(window).load(function () {
        $('img').each(function () {
            var error = false;
            if (!this.complete) {
                error = true;
            }
            if (typeof this.naturalWidth != "undefined" && this.naturalWidth == 0) {
                error = true;
            }
            if (error) {
                this.src = "images/01.jpg";
            }
        });
    });
上一篇 下一篇

猜你喜欢

热点阅读