Http://blog.csdn.net/junval/archive/2007/08/29/1763541.aspx
Code
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "textarea. aspx. cs" inherits = "textarea" %>
<! 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 runat = "server">
<Title> Implementation of textarea adaptive height without borders and scroll bars </title>
<Style type = "text/CSS">...
. Info {...}{
Font-size: 12px;
Overflow: hidden;
Background-color: # ffffcc;
Color: black;
Width: 100%;
Line-Height: 12px;
Padding-Right: 5px;
Padding-left: 5px;
Font-family: courier;
Width: 100%;
Letter-Spacing: 0;
Border-style: none;
}
</Style>
<Script language = "JavaScript" type = "text/JavaScript">
Function setrows (OBJ ){
VaR textarea = OBJ;
VaR Cols = textarea. Cols;
VaR STR = textarea. value;
STR = Str. Replace (/? /,"");
VaR lines = textarea. Rows;
VaR chars = 0;
For (I = 0; I <Str. length; I ++ ){
VaR c = Str. charat (I );
Chars ++;
If (C = "")
{
Lines ++;
}
Else
{
If (I> lines * (Cols/2) // in Chinese mode, except 2. If the English character is entered, change it to 1.
{
Lines ++;
}
}
}
Textarea. setattribute ("rows", lines );
Textarea. style. Height = lines * 12 + "PX ";
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Textarea id = 'logc' onkeyup = 'setrows (this) 'class = 'info' Cols = '75' rows = '12'> you can adjust the height according to the content. </textarea>
</Div>
</Form>
</Body>
</Html>