Home >Web Front-end >JS Tutorial >When the element is not displayed and width/height is set, currentStyle is used in IE to obtain the auto_javascript technique.

When the element is not displayed and width/height is set, currentStyle is used in IE to obtain the auto_javascript technique.

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-16 16:50:141241browse

We know that to get the actual width and height of an element, you can use the currentStyle attribute in IE. But if the width and height of the element are not explicitly set, then this attribute will not be obtained, and the obtained value will be auto. As follows

Copy the code The code is as follows:

abcd

<script> <br>var div = document.getElementsByTagName('div')[0]; <br>alert(div.currentStyle.width); <br>alert(div.currentStyle.height); <br> </script>

The output in IE6/7/8/9 is auto. If the displayed width and height are set, the output is the actual width and height. As follows

1, set the inline style attribute
Copy the code The code is as follows:

abcd

<script> <br>var div = document.getElementsByTagName('div')[0]; <br>alert(div.currentStyle.width); <br>alert(div.currentStyle.height); <br></script>

2, set by embedding the style tag on the page
Copy code The code is as follows:


abcd

<script> <br>var div = document.getElementsByTagName ('div')[0]; <br>alert(div.currentStyle.width); <br>alert(div.currentStyle.height); <br></script>

Both will output: 100px, 50px
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn