代码如下:
<tr> <td> <textarea style= 'border: 1px solid #94BBE2;width:98%; padding:2px; line-height:120%; ' cols= "3 " rows=15 onpropertychange= 'this.style.posHeight=this.scrollHeight ' id= 'hfnrid2 ' onfocus= 'this.style.posHeight=this.scrollHeight ' readonly= "readonly " > 是呀,实际上我们是没有办法去真的解释什么的\r\n,还是那样,如果我们可以,那么我们就继续,\r\n再聊吧. </textarea> </td> </tr>
<script> document.getElementById( "hfnrid2 ").focus(); </script>
<!--就是要求textarea自适应文字内容高度-->
这段话在本地调试没有问题,但是长传到网站以后,就不能够正常显示了,不能够自适应高度,而是非常窄的一条?怎么回事,有办法解决吗?
------解决方案--------------------
=========自适应文字内容高度测试.htm 代码==============
<html>
<head>
<title> textarea 自适应文字内容高度测试 </title>
<SCRIPT language= "javascript ">
<!--
function autofix()
{
for (i=1;i <=5;i++)
{
ob = document.getElementById( 'hfnrid ' + i);
ob.style.posHeight = ob.scrollHeight + 2;//居然有误差 2 ??
}
}
-->
</SCRIPT>
<STYLE>
<!--
TEXTAREA {border: 1px solid #94BBE2;width:98%; padding:2px; line-height:120%;}
-->
</STYLE>
</head>
<body onload= "autofix() ">
<TEXTAREA ID= "hfnrid1 " READONLY= "readonly "> 1 </TEXTAREA>
<TEXTAREA ID= "hfnrid2 " READONLY= "readonly "> 2
2 </TEXTAREA>
<TEXTAREA ID= "hfnrid3 " READONLY= "readonly "> 3
3
3 </TEXTAREA>
<TEXTAREA ID= "hfnrid4 " READONLY= "readonly "> 4
4
4
4 </TEXTAREA>
<TEXTAREA ID= "hfnrid5 " READONLY= "readonly "> 5
5
5
5
5 </TEXTAREA>
</body>
</html>