【发布时间】:2015-01-04 22:47:26
【问题描述】:
我已经构建了一个 Angular 应用程序,它利用 Instagram API 来提取图像。如果用户稍后删除图像,我最终会得到损坏的图像(404)。 我尝试使用 jQuery 隐藏包含这些(损坏的)图像的 div,但它们仍然出现。
我已将以下 jQuery 放置在我在“index.html”文件中引用的“custom.js”文件中:
$(document).ready(function() {
$("img").error(function() {
$(this).parent().hide();
});
});
我在'index.html'的头部引用jQuery然后'custom.js'如下:
<script src="libs/jquery/dist/jquery.min.js"></script>
<script src="js/custom.js"></script>
...这是我尝试将此 jQuery 应用到的 html:
<a ng-href="{{image.link}}" target="_blank" title="{{image.text}}"><img ng-src="{{image.img}}" alt="" class="img-responsive" ng-style="homeColors" id="image"></a>
【问题讨论】:
-
为什么不删除它?您无需再次显示。
-
@cychoi,删除也是一种选择。问题是上面的jQuery目前根本不工作,我不知道为什么。
-
您提供的代码有效。在这里查看:jsfiddle.net/fqxw0dqg
-
@cychoi,很有趣。我想知道我的图像位于
ng-repeat中是否会导致 jQuery 无法工作。 -
不确定。我从来没有使用过 angularJS,所以我不能这么说。如果您可以在问题中提供更多代码,这里的人可能会提供帮助。
标签: javascript jquery html angularjs