开发者

How to get the width and height of an img element where width and height have not been set?

开发者 https://www.devze.com 2023-02-23 02:40 出处:网络
How to get the width and height of an img element where width and height ha开发者_如何转开发ve not been set?They don\'t have to be explicitly set by CSS:

How to get the width and height of an img element where width and height ha开发者_如何转开发ve not been set?


They don't have to be explicitly set by CSS:

var img = document.getElementById("my_img");
var height = img.height;
var width = img.width;

Just like that, you have the height and width of your image element.


Give an Id to the image(myImage) in the HTML and then ,

<img src="myimagejpg" id="myImage"/>

the following script will give the actuall height and width of the image...

var myImage = document.getElementById("myImage ");
var myheight= myImage .height;
var mywidth = myImage .width;
0

精彩评论

暂无评论...
验证码 换一张
取 消