function getImgSize(imgSrc)
{
var newImg = new Image();
newImg.src = imgSrc;
var height = newImg.height;
var width = newImg.width;
alert ('The image size is '+width+'*'+height);
}
</script>
使用
onclick="getImgSize('images/testout_r1_c2.jpg')"
使用到javascript的Image物件,用他的height和width屬性去求出長寬
下面有Image物件的內容
JavaScript Image Object
The JavaScript Image Object is a property of the document object.
Properties
- border - The width of the border around the image in pixels.
- complete - A boolean value which identifies whether an image is completely loaded yet.
- height - The read only height of the image in pixels.
- hspace - The read only amount of horizontal space to the left and right sides of the image.
- lowsrc - The read or write string giving the URL of an alternate image for low resolution screen display.
- name - The assigned name of the image.
- prototype - Used for adding user-specified properties to the image.
- src - The URL of the image to be displayed. It is a read/write string.
- vspace - The read only vertical space above and below the image.
- width - The read only width of the image in pixels.
Events
--
轉自 http://kaohsing.blogspot.com/2010/03/javascript.html
留言列表