In IE, especially in the current div + css method, the height of the div is usually not defined. This is usually used when you need to obtain the height of the div after adding the div content.
In use, sometimes the offsetHeight value is 0, but if you use various JS debugging tools for debugging, you can also see the value in the object (if the direct point to offsetHeight is not a value, but if it is an object that has a value, press enter in the debugger to view the object and the object has been refreshed, so there is a value .)
For example
Copy codeThe Code is as follows:
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html>
<Head>
<Script language = 'javascript '>
Window. attachEvent ("onload", function () {_ resizeScroll2 ();});
Window. onresize = function () {winresize ();};
Function _ resizeScroll2 (){
Var html1 = '<div id = "divcj" style = "margin-top: 15px; font-size: 10px; width: 400px;">'
+ '<Div style = "float: left; width: 50px;"> test </div>'
+ '<Div style = "float: left; width: 320px;"> danielinbiti </div>'
+ '</Div>'
+ '<Div id = "divcj2" style = "margin-top: 15px; font-size: 10px; width: 400px;">'
+ '<Div style = "width: 320px;"> danielinbiti </div>'
+ '</Div>'
Document. getElementById ('outer'). innerHTML = html1;
Document. getElementById ('divcj1'). style. display = 'none ';
Alert (document. getElementById ('divcj1'). offsetHeight );
}
</Script>
</Head>
<Body>
<Div id = 'outer'> </div>
</Body>
</Html>
If the divcj height is obtained, the value 0 is obtained in onload. Because divcj has a float layout.
In this case, if the div is simple, you can use the hidden layer, such as divcj2, to remove the float and obtain the same height as divcj.