<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-width
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 the bounce occurs
_info.append (_max);
}
_val= $ (this). Val ();
_cur = Getbytelen (_val);
if (_cur = = 0) {//when the default value length is 0 o'clock, you can enter the number as the default maxlength value
_info.text (_max);
} else if (_cur < _max) {//when the default value is less than the limit number, you can enter a number of max-cur
_info.text (_max-_cur);
} else {//when the default value is greater than or equal to the limit number
_info.text (0);
$ (this). Val (Getbyteval (_val,_max)); Intercept values within a specified byte length
}
});
});
</script>
jquery number of characters (number letter length is 1, Chinese record is 2, over length auto-intercept)