Javascript 找到正确的图像宽度和高度

Javascript 找到正确的图像宽度和高度,javascript,Javascript,现在我得到了图像的宽度和高度时,加载功能的img。我的问题是,图像原始宽度=500px,但document.getElementId(id).offsetWidth仅给出300px,高度也是如此。请帮助我如何获得图像的原始宽度和高度至少Gecko-(Firefox)和基于WebKit(Safari,Chrome)的浏览器应该为图像元素实现属性自然宽度和自然高度: var image = document.getElementById("imageid"); if (image.naturalHe

现在我得到了图像的宽度和高度时,加载功能的img。我的问题是,图像原始宽度=500px,但document.getElementId(id).offsetWidth仅给出300px,高度也是如此。请帮助我如何获得图像的原始宽度和高度

至少Gecko-(Firefox)和基于WebKit(Safari,Chrome)的浏览器应该为图像元素实现属性
自然宽度
自然高度

var image = document.getElementById("imageid");
if (image.naturalHeight === undefined) {
  alert("Your browser doesn't support this example!");
} else {
  var message = "The original size of the image:";
  message += "\n height: " + image.naturalHeight + "px";
  message += "\n width: " + image.naturalWidth + "px";
  alert(message);

}

很抱歉,我的浏览器不支持naturalHeight和naturalWidth..

@c0mrade,因为如果图像已缩放,则image.width和image.height属性将返回缩放大小,而不是原始大小。至少在firefox中是这样。