字数限制

2019-02-21  本文已影响0人  梦里梦不到的梦_b5c8

js:

$("#area").on("input propertychange", function () {

var $this =$(this),

        _val = $this.val(),

        count ="";

    if (_val.length >600) {

$this.val(_val.substring(0, 600));

    }

count =600 - $this.val().length;

    $("#text-count").text(count);

});

html:

<textarea class="form-control" name="content" id="area" placeholder="请输入文字内容(600字之内)">

<div class="bottom">

    还可以输入<span id="text-count" style="color:red">600</span>/600,按下Enter键换行

</div>

上一篇 下一篇

猜你喜欢

热点阅读