/*
Tofu is made of excellent products
Http://www.asp888.net bean curd technology station
If reprinted, Please retain the complete copyright information
*/
We know that the input length of a text input box must be limited sometimes. We can use maxlength to limit the input length of text and password.
The input length of the input box of the type is limited. However, when we use the maxlength attribute for textarea, we are sorry.
This attribute does not work in textarea.
Is there any way? The answer is yes, yes! What Is HTC ?? Simply put, HTC is the HTML component.
The expression capability is not strong. Let's take a look at the example below.
Test.html:
<Form method = "Post">
<P> <input type = "text" size = "30" maxlength = "50" name = "T1">
<Textarea name = "S1" rows = "4" Cols = "30" maxlength = "50" style = "behavior: URL (maxlength. HTC)"> </textarea>
</Form>
We have noticed that we have never seen such a usage before: Style = "behavior: URL (maxlength. HTC)". Let's take a look.
The following HTC content
<Public: component id = "bhvmaxlength" Urn = "maF: maxlength">
<Public: property name = "maxlength"/>
<Public: attach event = "onkeypress" handler = "dokeypress"/>
<Public: attach event = "onbeforepaste" handler = "dobeforepaste"/>
<Public: attach event = "onpaste" handler = "dopaste"/>
<Script language = "jscript">
// Keep user from entering more than maxlength characters
Function dokeypress (){
If (! Isnan (maxlength )){
Maxlength = parseint (maxlength );
VaR OTR = element.doc ument. selection. createRange ();
// Allow user to type character if at least one character is selected
If (OTR. Text. length> = 1)
Event. returnvalue = true;
Else if (value. length> maxLength-1)
Event. returnvalue = false;
}
}
// Cancel default behavior
Function dobeforepaste (){
If (! Isnan (maxlength ))
Event. returnvalue = false;
}
// Cancel default behavior and create a new paste routine
Function dopaste (){
If (! Isnan (maxlength )){
Event. returnvalue = false;
Maxlength = parseint (maxlength );
VaR OTR = element.doc ument. selection. createRange ();
VaR iinsertlength = maxlength-value. Length + OTR. Text. length;
VaR sdata = Window. clipboardData. getdata ("text"). substr (0, iinsertlength );
OTR. Text = sdata;
}
}
</SCRIPT>
</Public: component>
About htc content on the msdn site is very detailed, interested friends can go to http://msdn.microsoft.com/workshop/components/htc/reference/htcref.asp
Author: tofu (original)