从url获取图像大小的函数:alert()工作但不返回

时间:2014-06-25 19:03:31

标签: javascript jquery image

今天我需要一个从URL获取图像大小(宽度和高度)的函数。我已经在stackoverflow上找到了一些,但是当我尝试使用它时,我总是得到#34; undefined"。我改变了#34后的功能;返回"到"警告"它工作正常,但我不知道为什么它不想回归。你能帮助我吗?

我的功能(不工作):

function getImgSize( title, url ){   
  var tmpImg = new Image();
  tmpImg.src = url;
  $(tmpImg).one('load',function(){
    orgWidth = tmpImg.width;
    orgHeight = tmpImg.height;
    return orgWidth+"x"+orgHeight;
  });
}

工作一:

function getImgSize( title, url ){   
  var tmpImg = new Image();
  tmpImg.src = url;
  $(tmpImg).one('load',function(){
    orgWidth = tmpImg.width;
    orgHeight = tmpImg.height;
    alert(orgWidth+"x"+orgHeight);
  });
}

0 个答案:

没有答案