是图像存在于文件夹中 [英] is image exist on folder

查看:60
本文介绍了是图像存在于文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有人帮我如何编写代码,无论图像是否存在于文件夹内或使用JAVASCRIPT



以及我们如何处理图像文件夹内不存在

Does any one help me how to write a code whether the image is exist inside the folder or not using JAVASCRIPT

and also how we handle it if the image is doesn't exist inside the folder

推荐答案

function urlExists(testUrl) {
 var http = jQuery.ajax({
    type:"HEAD",
    url: testUrl,
    async: false
  })
  return http.status;
      // this will return 200 on success, and 0 or negative value on error
}





然后使用





Then use

if(urlExists('urlToImgOrAnything') == 200) {
    // success
}
else {
    // error
}


尝试

Try
function testImage(URL) {
    var tester=new Image();
    tester.onLoad=isGood;
    tester.onError=isBad;
    tester.src=URL;
}

function isGood() {
    alert('That image exists!');
}

function isBad() {
    alert('That image does no exist!');
}





脚本取自这里 - http://www.irt.org/script/52.htm [ ^ ]。


这篇关于是图像存在于文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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