jquery判断显示剩下可输入内容字数

<script>

    $(function(){



        //先选出 textarea 和 统计字数 dom 节点

        var wordCount = $("#wordCount"),

            textArea = wordCount.find("textarea"),

            word = wordCount.find(".word");

        //调用

        statInputNum(textArea,word);



    });

    /*

    * 剩余字数统计

    * 注意 最大字数只需要在放数字的节点哪里直接写好即可 如:<var class="word">200</var>

    */

    function statInputNum(textArea,numItem) {

        var max = numItem.text(),

            curLength;

        textArea[0].setAttribute("maxlength", max);

        curLength = textArea.val().length;

        numItem.text(max - curLength);

        textArea.on('input propertychange', function () {

            numItem.text(max - $(this).val().length);

        });

    }

</script>

发布了44 篇原创文章 · 获赞 59 · 访问量 16万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章