完美解决textarea字数限制[转载]

2018-07-27  本文已影响0人  willeny

原文地址:https://blog.csdn.net/fb_01/article/details/51026774

    <textarea name="detail" id="detail" cols="" rows="" placeholder="请输入内容" style="height: 250px;"></textarea>
    <p><span id="text-count">255</span>/255</p>
    <script type="text/javascript">
            $('#detail').on("input propertychange",function(){
                var this = $(this);
                _val = $this.val(),
                count = "";
                if(_val.length > 255){
                    $this->val(_val.substring(0,255));
                }
                count = 255 - $this.val().length;
                $("#text-count").text(count);
            });
     </script>
html代码截图
js代码截图 效果图
上一篇 下一篇

猜你喜欢

热点阅读