IMG NG-SRC形象是永远不会结束 [英] img ng-src image is never ending

查看:194
本文介绍了IMG NG-SRC形象是永远不会结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有类似下面

 < IMG WIDTH =100HEIGHT =177NG-秀=file.fileNameNG-SRC =file.fullPath级=IMG-缩略图 ALT =测试的onerror =this.src = $(本).attr('altSrc')>文件名是abc.png
完整路径是/data/uploads/abc.png

不过,在src是永无止境的。下面是日志。

 信息2015年10月2日03:02:40-6357939496072691129  - 请求:GET本地主机:26264 /未定义
信息2015年10月2日03:02:40-6357939496072691129 - 响应:获取本地主机:26264 /未定义未找到
信息2015年10月2日03:02:40-6357939496074282039 - 请求:GET本地主机:26264 /未定义
信息2015年10月2日03:02:40-6357939496074282039 - 响应:GET本地主机:26264 /未定义

如何prevent呢?


解决方案

 < IMG WIDTH =100HEIGHT =177NG-秀=file.fileNameNG- SRC =file.fullPath级=IMG-缩略图ALT =测试的onerror =this.src = $(本).attr('altSrc')>

的onerror 设置SRC的属性 altSrc ,但因为你还没有定义的 altSrc 它出现了错误,并再次导致循环。

要prevent循环,定义一个 altSrc 。以$ P $这种一般pvent,不要内联JavaScript这样。相反,定义背景图片在CSS中的图像元素。你永远不要这样,需要检查图像错误,因为加载的图像会简单地覆盖CSS背景图片。

I've something like below

<img width="100" height="177" ng-show="file.fileName" ng-src="file.fullPath" class="img-thumbnail" alt="test" onerror="this.src = $(this).attr('altSrc')">

fileName is "abc.png"
fullPath is "/data/uploads/abc.png"

But, The src is never ending.. below is the log.

INFO 2015-10-02 03:02:40-6357939496072691129 - Request: GET localhost:26264/undefined 
INFO 2015-10-02 03:02:40-6357939496072691129 - Response: GET localhost:26264/undefined Not Found 
INFO 2015-10-02 03:02:40-6357939496074282039 - Request: GET localhost:26264/undefined 
INFO 2015-10-02 03:02:40-6357939496074282039 - Response: GET localhost:26264/undefined

How to prevent this?

解决方案

<img width="100" height="177" ng-show="file.fileName" ng-src="file.fullPath" class="img-thumbnail" alt="test" onerror="this.src = $(this).attr('altSrc')">

Your onerror sets the src to the attribute altSrc, but since you haven't defined altSrc it errors out again and causes the loop.

To prevent the loop, define an altSrc. To prevent this in general, don't inline javascript like this. Instead define a background image for your image element in CSS. That way you don't ever need to check for image errors, since the loaded image will simply cover the CSS background image.

这篇关于IMG NG-SRC形象是永远不会结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆