This question already has an answer here:
(这个问题已经在这里有了答案:)
trying to get dimenstions (eg 600x300) from an image using javascript.
(尝试使用javascript从图像中获取尺寸(例如600x300)。)
I am not sure how to return the data because it's not working.(我不确定如何返回数据,因为它无法正常工作。)
Do I need a callback, and how ?(我需要回调,如何?)
<script>
function getMeta(url){
var img = new Image();
var res = img.onload = function(){
var ret = this.width+'x'+ this.height;
alert(ret);
return ret;
};
img.src = url;
return res;
}
var meta = getMeta('https://upload.wikimedia.org/wikipedia/en/a/a9/Example.jpg');
alert(meta);
</script>
ask by Mike Q translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…