1. $ (' textarea#txtprizenote '); Represents the name of the textarea control
2. ' Span ' shows the label of the remaining words
Html:
Copy Code code as follows:
<div>
<textarea id= "Txtprizenote" runat= "Server" height= "74px" width= "480px" maxlength= "10"
Style= "width:480px; height:74px; Float:left "></textarea>
<span style= "color:red;" >*</span><br/>
Remaining words: <span id= "showmsg" style= "color:red" ></span>
</div>
Copy Code code as follows:
<script type= "Text/javascript" >
Returns the byte length of Val
Function Getbytelen (val) {
var len = 0;
for (var i = 0; i < val.length; i++) {
if (Val[i].match (/[^\x00-\xff]/ig)!= null)//Full angle
Len + 2;
Else
Len + 1;
}
return Len;
}
Returns the value of Val within the specified byte length max
Function Getbyteval (val, max) {
var returnvalue = ';
var bytevallen = 0;
for (var i = 0; i < val.length; i++) {
if (Val[i].match (/[^\x00-\xff]/ig)!= null)
Bytevallen + 2;
Else
Bytevallen + 1;
if (Bytevallen > Max)
Break
ReturnValue + = Val[i];
}
Return returnvalue;
}
$ (function () {
var _area = $ (' textarea#txtprizenote ');
var _info = _area.next ();
var _max = _area.attr (' maxlength ');
var _val;
_area.bind (' KeyUp change ', function () {//bind KeyUp and change events
if (_info.find (' span '). Size () < 1) {//avoid inserting a message every time it bounces
_info.append (_max);
}
_val = $ (this). Val ();
_cur = Getbytelen (_val);
if (_cur = = 0) {//when the default value is 0 o'clock, the number of entries can be the default maxlength value
_info.text (_max);
else if (_cur < _max) {//when the default value is less than the limit, the number can be entered as Max-cur
_info.text (_max-_cur);
else {//when the default value is greater than or equal to the limit
_info.text (0);
$ (this). Val (Getbyteval (_val,_max)); Intercepts values within a specified byte length
}
});
});
</script>