现在的位置: 首页 > 综合 > 正文

js设置指定div的高度

2018年04月09日 ⁄ 综合 ⁄ 共 418字 ⁄ 字号 评论关闭

<script type="text/javascript">

function $(id){       //获指定id的element,方法形如jQuery

      return document.getElementById(id);

}

 

function getHeight(){

      var a=$("p_count").offsetHeight;            //得到p_count目前的高

 

      if(a>1000)

      {

       //alert(a);

      }

      else{

           $("p_count").style.height="900"+"px"; //设定定高

     }

}

 

 

window.onload=function(){

       getHeight();

}

</script>

 

<div id="p_count" style="border:1px solid #ccc">lalala</div>

抱歉!评论已关闭.