BelowCodeIt is directly copied from the vs2005 development environment. You can directly copy it and run it.
ThisProgramThere is still a problem when processing Chinese characters. it is limited to 120 characters and 60 Chinese characters, but it is possible that you can only enter 55 characters. It is strange that you are looking for the reason. it will be updated later. if you can see it, please help change it... thank you .....
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default2.aspx. cs" inherits = "default2" %>
<! 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> No title page </title>
<SCRIPT type = "text/JavaScript">
Function fucchecklength (strtemp)
{
VaR I, sum;
Sum = 0;
For (I = 0; I <strtemp. length; I ++)
{
If (strtemp. charcodeat (I)> = 0) & (strtemp. charcodeat (I) <= 255 ))
Sum = sum + 1;
Else
Sum = sum + 2;
}
Return sum;
}
Function showleft (){
VaR lenstring, lenstringi, strings;
Lenstring = fucchecklength (document. getelementbyid ("textbox1"). value );
Lenstringi = lenstring;
If (lenstring & gt; 120 ){
Alert ("the length of the entered characters cannot exceed 120 (60 Chinese characters )! ");
Strings = Document. getelementbyid ("textbox1"). value;
While (lenstringi> 120 ){
If (strings. charcodeat (strings. Length)> = 0) & (strings. charcodeat (strings. Length) <= 255 )){
Lenstringi = LenStringI-1;
}
Else {
Lenstringi = LenStringI-2;
}
Strings = strings. substring (0, (strings. Length-1 ));
}
Document. getelementbyid ("textbox1"). value = strings;
Return false;
}
Document. getelementbyid ("button1"). value = 250-lenstring;
}
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Div>
<Asp: textbox id = "textbox1" runat = "server" Height = "156px" textmode = "multiline" width = "326px" onkeyup = "Return showleft (); "> </ASP: textbox>
<Input id = "button1" type = "button" value = "120"/>
</Div>
</Form>
</Body>
</Html>