我将图像路径的值从文本框扔到boxvalue,并想要使用javascript验证图像是否存在.
var boxvalue = $('#UrlQueueBox').val();
Run Code Online (Sandbox Code Playgroud)
我浏览了stackoverflow并找到了下面的图像宽度/高度,但不想使用它.
var img = document.getElementById('imageid');
Run Code Online (Sandbox Code Playgroud)
我如何验证它是否真的是图像路径中的图像?
我想知道我们是否可以使用angular2绑定或插入图像标签上的onError,
在app.component.ts上:
imageUrl:string;
constructor( ) {
this.imageUrl = 'graphics/placeholder.gif';
}
Run Code Online (Sandbox Code Playgroud)
在app.component.html上:
<img class="img-responsive" [src]="'graphics/image-1.jpg'" onError="imageUrl"/>
Run Code Online (Sandbox Code Playgroud)
以下方法有效.
<img class="img-responsive" [src]="'graphics/image-1.jpg'" onError="this.src='graphics/placeholder.gif'"/>
Run Code Online (Sandbox Code Playgroud)
但是,当我们在应用程序上使用许多图像时,我想将其作为一个简单的动态解决方案,我也找到了这个答案,
但由于某种原因不起作用,我不知道我在这里做错了什么
它与Angular 2完全相同- 检查图像URL是有效还是坏了.
我怎样才能在vuejs中实现这个?