javascript設(shè)置高的方法:首先獲取指定id的element;然后得到“p_count”目前的高;最后通過(guò)“$("p_count").style.height="900"+"px";”設(shè)置定高即可。
本文操作環(huán)境:windows7系統(tǒng)、javascript1.8.5版、Dell G3電腦。
javascript怎么設(shè)置高?
js設(shè)置指定div的高度
代碼如下:
<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"; //設(shè)定定高 } } window.οnlοad=function(){ getHeight(); } </script> <div id="p_count" style="border:1px solid #ccc">lalala</div>
【