运行代码框<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <title>练习文档01</title> <style type="text/css"> <!-- body{ margin:0px;padding:0px; } .Div_top{ width:100%; background:#93beff; } .Div_bottom{ width:100%; background:#ff00fc; } .Div_Left{ position:absolute; width:200px; background:#ff6000; left:0px; } .Div_Right{ margin-left: 200px; background:#00c17b; } --> </style> <script> function SameH(leftDiv,rightDiv) { var a=document.getElementById(leftDiv); var b=document.getElementById(rightDiv);document.write(a.clientHeight+'px'); document.write(b.clientHeight+'px'); document.write(a.scrollHeight+'px'); document.write(b.scrollHeight+'px');if (a.scrollHeight < b.scrollHeight) { a.style.height= b.scrollHeight; } else { b.style.height= a.scrollHeight; } } </script></head> <body> <div class="Div_top">这是顶部的div</div> <div id="Div1" class="Div_Left">11111<br>222222<br>33333333<br>444444444<br>555555555</div> <div id="Div2" class="Div_Right">22222<br>dsaf</div> <div class="Div_bottom">---------------------------------这是底部的DIV,在左中右中DIV不等高的情况下会跑上去重叠了<br>----------------------------------------我现在想用一个JavaScript代码来令左右两半的Div等高<br><br>(注意:中左中右两个DIV的高度是无法事先确定的)<br>为什么这个JavaScript在FireFox无效呢?</div> <script> SameH("Div1","Div2"); </script> </body> [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]