Home  >  Article  >  Web Front-end  >  The phenomenon that offsetHeight is 0 in OnLoad_javascript skills

The phenomenon that offsetHeight is 0 in OnLoad_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:28:101409browse

When using IE, especially in the current div css method, the height of the div is often not defined. This is because when you need to obtain the height of the div after adding the div content, you often need to use offsetHeight.

In use, sometimes you will encounter the phenomenon that offsetHeight is obtained as 0, but if you use various JS debugging tools to debug, you can see the value in the object (it is worthless if you point it directly to offsetHeight , but if the object view has a value, the object has been refreshed by pressing Enter in the debugger, so it has a value)

For example, the following fragment

Copy code The code is as follows:











If you get the height of divcj, then onload What is obtained is 0. Because there is a float layout under divcj.
If the div is simple, you can use a hidden layer, such as divcj2 here. After removing the float, the height obtained will be the same as divcj.
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