jQuery Plugin: Characters lenght
Postado por: Pedro Rogério emVocê por um acaso já viu aqueles contadores de caracteres restantes em formulários e não teve a menor idéia ou saco pra fazer aquilo, pois bem, procurando no google achei um plugin para jQuery que faz isso de uma forma bem simples, mas sua aplicação é somente a inputs, não sendo aplicado a textareas:
jQuery.fn.counter = function() {
$(this).each(function() {
var max = $(this).attr('maxlength');
var val = $(this).attr('value');
var cur = 0;
if(val) // value="", or no value at all will cause an error
cur = val.length;
var left = max-cur;
$(this).after("<div class='counter'>"
+ left.toString()+"</div>");
// You can use something like this to align the
// counter to the right of the input field.
var c = $(this).next(".counter");
c.width(40);
c.css("position","relative");
c.css("top",-$(this).height()-8);
c.css("left",$(this).width()+8);
c.css("background","yellow");
$(this).keyup(function(i) {
var max = $(this).attr('maxlength');
var val = $(this).attr('value');
var cur = 0;
if(val)
cur = val.length;
var left = max-cur;
$(this).next(".counter").text(left.toString());
return this;
});
});
return this;
}














