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="請輸入文字內(nèi)容(600字之內(nèi))">
<div class="bottom">
? ? 還可以輸入<span id="text-count" style="color:red">600</span>/600,按下Enter鍵換行
</div>