Показать сообщение отдельно
  #3 (permalink)  
Старый 22.03.2011, 21:59
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,072

Вариант установки и индикации maxlength для textarea и input ...
<!DOCTYPE html>
<html>
<head>
  <title></title>
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
  <script type="text/javascript">
 (function (a) {
    a.fn.setMaxlength = function () {
        var e = arguments;
        return this.each(function (i) {
                var b = a(this),
                c = e[i]||"50";
            b.attr("maxlength")&&b.attr("maxlength", c);
            var d = a("<span />").css({
                color: "#FF0000"
            });
            b.after(d);
            d.html("({num} out of {max})".replace("{num}", b.val().length).replace("{max}", c));
            b.bind("keypress keydown keyup paste click mouseup", function (e) {
                var g = a(this).val();
                 if (g.length >= c){
                 a(this).val(g.substring(0,c));
            d.html("Max = "+c);
                }

           else     d.html("({num} out of {max})".replace("{num}", g.length).replace("{max}", c))
            })
        })
    }
})(jQuery);

 $(function() {
 $("textarea, input").setMaxlength(60,15,10);
 //$("#short_description").setMaxlength(60);
});
</script>
</head>

<body>
<textarea id="short_description"  cols="60"></textarea>
<br />
<input name="a" />
<br />
<input name="b" />
<br />
<input name="c" />
<br />
<input name="d" />
<br />
</body>
</html>
Ответить с цитированием