0
不返回變量我試圖檢測圖像的寬度,我有網址:功能jQuery中
var getWidth = function(url){
var i = new Image;
i.onload = function(){
var width = (this.width);
alert(width); // width defined here
return width;
}
i.src = url;
}
var theWidth = getWidth(url);
alert(theWidth); // undefined here
我需要的寬度之前,我加載圖片,因此我可以修改它的容器。我覺得這裏有一個明顯的解決方案,但我無法弄清楚。謝謝!
我沒有看到任何jQuery? –
你不能從異步回調中返回。 –