1、首先我们在桌面创建一个文件index.html,并随便截取一个桌面图片(500*250)的图片,并命名为car.gif:






5、修改index.html,贴入以下代码:function getNaturalWidth(img) { var image = new Image() image.src = img.src return image.height; } var img = document.getElementById('img'); var result = getNaturalWidth(img); alert(result);浏览器查看效果,发现显示的图片真实高度:

6、还有一种html5的高级方法,缺点是有写浏览器可能不支持:var img = document.getElementById('img'); var result = img.naturalHeight; alert(result);

7、本文讲述的是height,关于width道理是一样的,同学们可以自行脑补或练习。