日期:2014-05-18 浏览次数:20519 次
<!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" />
<script type="text/javascript">
function $(o)
{
if(typeof(o)=="string")
return document.getElementById(o);
return o;
}
function autoContent(o,dHeight)
{
var obj=$(o);
obj.style.overflow="auto";
if(parseInt(obj.scrollHeight)>=dHeight)
{
obj.style.height=dHeight+"px";
}
else
{
obj.style.height="auto";
}
}
setInterval(function(){autoContent("atc",150);},10);
</script>
</head>
<body>
<center>
<input type="button" onclick="$('atc').innerHTML+='New Text<br/>'" value="Add Text"/>
</center>
<div style="width:200px;height:auto;border:1px solid red;margin:0px auto;padding-left:5px;" id="atc">
this is Content<br/>
</div>
</body>
</html>
------解决方案--------------------
也不用js那么麻烦啊,就是设定固定的高啊,再一句OVERFLOW-Y: auto就解决了啊
------解决方案--------------------
接分接分`
------解决方案--------------------
不设置高度属性,在DIV加几个回车也许可以达到你的效果