JS獲取DIV動態高度,並賦值到其style樣式中

<head> 

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> 

<title>JS獲取DIV動態高度,並賦值到其style樣式中</title> 

</head> 

<script type="text/javascript"> 

         function $(id){  

           return document.getElementById(id)  

        }  

        function getHeight() {  

          alert($("hidden").offsetHeight + "px");  

          $("pinglun").style.height=$("hidden").offsetHeight + "px";            

        }  

      window.onload = function() {  

          getHeight();  

         }  

   </script> 

   <style> 

   #hidden { width:100px; background:#99CC00; height:400px; float:left}  

   #pinglun { width:500px; height:auto; background:#FFCCCC; float:left; margin-left:5px;}  

</style> 

 <body> 

<div id="hidden">hidden</div> 

  <div id="pinglun" >評論數據載入中……</div> 

</body> 

</html> 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章