jquery textarea输入字符字数提示

效果:

html代码:

<textarea id="assayInfo" name="assayInfo" rows="3" cols="34" maxlength="30" placeholder="提示:请输入检查结果等相关信息,最多30个汉字"></textarea>
<span id="wordCount">30</span>/30

jquery代码:

$(document).ready(function() {
        var counter = $("#assayInfo").val().length; //获取文本域的字符串长度
        $("#wordCount").text(30 - counter);
        $(document).keyup(function() {
            var text = $("#assayInfo").val();
            var counter = text.length;
            $("#wordCount").text(30 - counter);    //每次减去字符长度
        });

    });

 

posted on 2015-05-11 10:35  依米艳  阅读(430)  评论(0编辑  收藏  举报

导航