<html>
    <header>
        <meta charset="utf-8">
        <title>测试实时字数显示</title>
    </header>
    <body>
        <div style="text-align: center;margin-top: 8%;">
            <h3>字数输入实时统计</h3>
            <textarea id="area" name="ss" placeholder="请输入文本内容" style="width: 50%;height: 35%;"></textarea>
            <p>当前字数为:<span id="text-count">0</span>,最大字数支持1.5万字(一个汉字、一个英语字母、一个标点符号均占用一个字符。)</p>
        </div>
    </body>

    <script src="https://cdn.bootcss.com/jquery/3.4.1/jquery.min.js"></script>
    <script type="text/javascript">
        /*字数限制 需要修改字数范围,下面15000换掉即可*/
        $("#area").on("input propertychange", function() {
            var $this = $(this),
                _val = $this.val(),
                count = "";
             if (_val.length > 15000) {
                $this.val(_val.substring(0, 15000));
             }
            count =$this.val().length;
            $("#text-count").text(count);
        });
    </script>
</html>
01-13 09:12