<Script language = "JavaScript" type = "text/JavaScript">
<! --
Function limitlength (value, bytelength, attribute)
{
VaR newvalue = value. Replace (/[^ \ x00-\ xFF]/g ,"**");
VaR length = newvalue. length;
// When the number of bytes entered is smaller than the set number of bytes
If (length * 1 <= bytelength * 1)
{
Return;
}
VaR limitdate = newvalue. substr (0, bytelength );
VaR COUNT = 0;
VaR limitvalue = "";
For (VAR I = 0; I <limitdate. length; I ++)
{
VaR flat = limitdate. substr (I, 1 );
If (flat = "*")
{
Count ++;
}
}
VaR size = 0;
VaR istar = newvalue. substr (bytelength * 1-1, 1); // check whether the checkpoint is "×"
// If the base point is X; determines whether X is an even number or an odd number within the base point.
If (count % 2 = 0)
{
// When the value is an even number
Size = count/2 + (bytelength * 1-count );
Limitvalue = value. substr (0, size );
}
Else
{
// When the value is an odd number
Size = (count-1)/2 + (bytelength * 1-count );
Limitvalue = value. substr (0, size );
}
Alert ("maximum input" + bytelength + "bytes (equivalent to" + bytelength/2 + "Chinese characters )! ");
Document. getelementbyid (attribute). value = limitvalue;
// Document. getelementbyid ("MSG"). innerhtml = bytelength;
Return;
}
// -->
</SCRIPT>
<Asp: textbox runat = "server" id = "txtcomment" Height = "77px"
Ontextchanged = "txtcomment_textchanged" textmode = "multiline" width = "307px"> </ASP: textbox>
<Textarea runat = "server" Cols = "50" rows = "10" name = "Explain" id = "Explain"> </textarea>
Add:
Explain. attributes ["onpropertychange"] = "limitlength (this. Value, 10, 'explain ')";
Complete page front-endCodeYes:
<% @ Page Language = "C #" autoeventwireup = "true" codefile = "default. aspx. cs" inherits = "_ default" %>
<% @ Register Assembly = "ajaxcontroltoolkit" namespace = "ajaxcontroltoolkit" tagprefix = "PC3" %>
<! 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> dropdownlist </title>
<Script language = "JavaScript" type = "text/JavaScript">
<! --
Function limitlength (value, bytelength, attribute)
{
VaR newvalue = value. Replace (/[^ \ x00-\ xFF]/g ,"**");
VaR length = newvalue. length;
// When the number of bytes entered is smaller than the set number of bytes
If (length * 1 <= bytelength * 1)
{
Return;
}
VaR limitdate = newvalue. substr (0, bytelength );
VaR COUNT = 0;
VaR limitvalue = "";
For (VAR I = 0; I <limitdate. length; I ++)
{
VaR flat = limitdate. substr (I, 1 );
If (flat = "*")
{
Count ++;
}
}
VaR size = 0;
VaR istar = newvalue. substr (bytelength * 1-1, 1); // check whether the checkpoint is "×"
// If the base point is X; determines whether X is an even number or an odd number within the base point.
If (count % 2 = 0)
{
// When the value is an even number
Size = count/2 + (bytelength * 1-count );
Limitvalue = value. substr (0, size );
}
Else
{
// When the value is an odd number
Size = (count-1)/2 + (bytelength * 1-count );
Limitvalue = value. substr (0, size );
}
Alert ("maximum input" + bytelength + "English (or" + bytelength/2 + "Chinese characters )! ");
Document. getelementbyid (attribute). value = limitvalue;
// Document. getelementbyid ("MSG"). innerhtml = bytelength;
Return;
}
// -->
</SCRIPT>
</Head>
<Body>
<Form ID = "form1" runat = "server">
<Textarea runat = "server" Cols = "50" rows = "10" name = "Explain" id = "Explain"> </textarea>
</Form>
</Body>
</Html>