开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜