如何获得动态加载图像的宽度和高度?

时间:2011-04-19 04:16:19

标签: jquery

如何获取动态加载图像的宽度和高度?

<img id="thumb_320" src="dscn6691_thumb_320.jpg">

1 个答案:

答案 0 :(得分:4)

尝试使用Image对象。老实说,我不确定兼容性。

所以有些代码可能如下:

var img = new Image();

img.onload = function(){
    alert('Width: ' + img.width +', Height: ' + img.height);
}

img.src = 'http://www.google.com/images/logos/ps_logo2.png';

实施例: http://jsfiddle.net/EQdxw/2/