方法一

function validateImage(pathImg) { // 判断图片地址是否有效
      let ImgObj = new Image()
  ImgObj.src = pathImg
  if (ImgObj.fileSize > 0 || (ImgObj.width > 0 && ImgObj.height > 0)) {
    return true
  } else {
    return false
  }
}

方法二

function validateImage(url) {    
    var xmlHttp ;
    if (window.ActiveXObject)
     {
      xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
     }
     else if (window.XMLHttpRequest)
     {
      xmlHttp = new XMLHttpRequest();
     } 
    xmlHttp.open("Get",url,false);
    xmlHttp.send();
    if(xmlHttp.status==404)
    return false;
    else
    return true;
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-05-18
  • 2021-06-15
  • 2021-12-30
  • 2022-12-23
  • 2021-07-22
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-12
  • 2022-02-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-22
相关资源
相似解决方案