jquery calculated text box input character number code
ASP tutorial X Files:
Introduce JS
<script type= "text/page special Effects" src= ". /script/maxlength.js "></script>
Because the textarea control is restricted, a hidden input must be used to control the length, because the TextArea MaxLength property takes the value of the character length that the user actually entered. If you are restricting input length, you do not need.
<asp:textbox textmode= "Multiline" wrap= "true" runat= "Server" id= "Positioninfo" rows= "width=" 825px "maxlength=" 3000 "></asp:textbox>
<br/> Up to 3000 words, can also enter <span id= "Descsize" >3000</span> Word
<input type= "hidden" name= "maxlength" value= "3000" id= "MaxLength"/>
jquery References:
<script type= "Text/javascript" >
$ (document). Ready (function () {
$ (' #<%=positioninfo.clientid%> '). Bind (' PropertyChange ', function () {
$ (this). MaxLength ({
' Feedback ': ' descsize ', ' useinput ': true
});
});
});
</script>
jquery Code
(function ($) {
$.fn.maxlength = function (settings) {
if (typeof settings = = ' String ') {
Settings = {Feedback:settings};
}
Settings = $.extend ({}, $.fn.maxlength.defaults, settings);
function Length (EL) {
var parts = El.value;
if (settings.words)
Parts = el.value.length? Parts.split (/s+/): {length:0};
return parts.length;
}
Return This.each (function () {
var field = this,
$field = $ (field),
$form = $ (field.form),
Limit = Settings.useinput? $form. Find (' # ' +settings.maxlength). Val (): $field. attr (' maxlength '),
$charsleft = $form. Find (' # ' +settings.feedback);
function Limitcheck (event) {
var len = length (this),
exceeded = Len >= limit,
Code = Event.keycode;
if (!exceeded)
Return
Switch (code) {
Case 8://Allow Delete
Case 9:
Case 17:
Case://Cursor keys
Case 35:
Case 37:
Case 38:
Case 39:
Case 40:
Case 46:
Case 65:
Return
Default
Return settings.words && code!= && code!= && len = = limit;
}
}
var updatecount = function () {
& nbsp; var len = length (field),
diff = limit-len;
& nbsp; $charsleft. html (diff | | "0");
Truncation Code
if (Settings.hardlimit && diff < 0) {
Field.value = settings.words?
Split by white spaces, capturing it in the result, then glue them
Field.value.split (/(S+)/, (limit*2)-1). Join ("):
Field.value.substr (0, limit);
Updatecount ();
}
};
$field. KeyUp (Updatecount). Change (Updatecount);
if (settings.hardlimit) {
$field. KeyDown (Limitcheck);
}
Updatecount ();
});
};
$.fn.maxlength.defaults = {
Useinput:false,
Hardlimit:true,
Feedback: ' Charsleft ',
Words:false,
MaxLength: ' MaxLength '
};
}) (jquery);