rows也可以在隐藏前看一下scrollHeight

解决方案 »

  1.   

    用字符串的总长度除以textarea的宽度就应该能得到行数。总长度你应该能得到,textarea的宽度是你开始就定好的。
      

  2.   

    取行数…………
    不知道这样行不行
    objTextarea.value.replace(/[^\n]/mg,'').length;
      

  3.   

    <head>
    <style>
    .textareaWidthoutBorder
    {
    height : expression(this.scrollHeight+5);
    overflow : hidden;
    }</style></head><body bgcolor=efefef>
    <table bgcolor=ccccc width=300 >
    <tr>
    <td>
    <textarea class=textareaWidthoutBorder style="width:100%" readOnly >将内容忠实显示
    与Pre的区别是内容过多,则会自动折行
    fdsafdas
    fdsaf
    折行折行折行折行折行折行折行折行折行折行折行折行折行折行折行折行折行折行折行折行折行折行 
    fdsa</textarea></td>
    </tr>
    </table>
     
    </body>
      

  4.   

    更强的一个:
    可以设置最大高度和最小高度, 超过设定最大高度则自动出现滚动条。<style>
    textarea.autoHeight{
      height : expression(scrollHeight+4<minH ? minH : Math.min(scrollHeight+4,maxH));
      overflow : auto;
    }
    </style>
    <textarea class=autoHeight style="width:500" minH="60" maxH="200">
    </textarea>