Javascript (循环中的图像)庞大的图像数组,希望显示图像是否确实存在,然后显示图像,否则删除/隐藏图像节点

Javascript (循环中的图像)庞大的图像数组,希望显示图像是否确实存在,然后显示图像,否则删除/隐藏图像节点,javascript,jquery,arrays,image,Javascript,Jquery,Arrays,Image,我有大量图像 事实上,我有点担心检查的图像,真的存在,也希望做一些事情,如果图像存在 如果没有找到,我正在做其他的工作 注意:如果一个映像正在服务器上检查,需要3分钟 然后如何处理其他图像的循环。 如果图像不存在,我会在图像下方找到:- 请给出一种可用于阵列中第n个图像的标准方法 var urlArray = [{productImage:'http://www.queness.com/resources/images/png/appleeeeeee_ex.png'},{productIma

我有大量图像

事实上,我有点担心检查的图像,真的存在,也希望做一些事情,如果图像存在 如果没有找到,我正在做其他的工作

注意:如果一个映像正在服务器上检查,需要3分钟 然后如何处理其他图像的循环。

如果图像不存在,我会在图像下方找到:-

请给出一种可用于阵列中第n个图像的标准方法

var urlArray =  [{productImage:'http://www.queness.com/resources/images/png/appleeeeeee_ex.png'},{productImage:'https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'},{productImage:'https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_cooooooolor_272x92dp.png'},{productImage:'https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'}];

<div>
  <img src="">  // actually this comes through urlArray  
</div>
var urlArray=[{productImage:'http://www.queness.com/resources/images/png/appleeeeeee_ex.png“},{productImage:”https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png“},{productImage:”https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_cooooooolor_272x92dp.png'},{productImage:'https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'}];
//实际上,这是通过URL数组实现的

提前感谢!

如果你想检查图像URL是否存在,你可以用javaScript试试, 它将逐个检查所有URL并调用回调函数,然后为下一个URL调用URL检查。 下一个URL将在一个URL完成后进行检查,无论需要多长时间

function isImageExists(imgSrc, callBackAfterCheck) {
   var img = new Image();
   img.onload = function() { callBackAfterCheck(true) };
   img.onerror = function() {callBackAfterCheck(false) };
   img.src = imgSrc;
}

var urlArray = [{productImage:'http://www.queness.com/resources/images/png/appleeeeeee_ex.png'},{productImage:'https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'},{productImage:'https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_cooooooolor_272x92dp.png'},{productImage:'https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'}];


var imageIndex = 0;
function callBackAfterCheck(status){
   if(status == true){
     //do your stuff here
     console.log('image Exist');
   }else{
     //do your stuff here
    console.log('image not Exist');
   }
   imageIndex++
   if(imageIndex < urlArray.length){
     var imageUrl = urlArray[imageIndex].productImage;
     isImageExists(imageUrl, callBackAfterCheck)
   }
}

var imageUrl = urlArray[imageIndex].productImage;
isImageExists(imageUrl, callBackAfterCheck);
函数isImageExists(imgSrc,检查后回拨){
var img=新图像();
img.onload=function(){callBackAfterCheck(true)};
img.onerror=函数(){callBackAfterCheck(false)};
img.src=imgSrc;
}
var urlArray=[{productImage:'http://www.queness.com/resources/images/png/appleeeeeee_ex.png“},{productImage:”https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png“},{productImage:”https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_cooooooolor_272x92dp.png'},{productImage:'https://www.google.co.in/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'}];
var指数=0;
函数回调后检查(状态){
如果(状态==真){
//在这里做你的事
log('image Exist');
}否则{
//在这里做你的事
console.log('映像不存在');
}
图像索引++
if(imageIndex
在这里,您可以传递图像源和检查源之后要执行的函数。 它将检查您的图像是否存在,您可以在回调函数中获取状态(true或false), 现在,您可以在回调函数中根据需要进行操作