如何获取动态加载图像的宽度和高度?
<img id="thumb_320" src="dscn6691_thumb_320.jpg">
答案 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';