不多说,直接上代码
<div class="copyEditorTitle copyCon">
<textarea id="editor_content" placeholder="请输入内容" name="editor_content"> </textarea>
</div>
<div style="background: #fff;display: flex;padding:5px 10px 5px 0;">
<span class="wi" style="float: right;text-align: right;color: #bababa;margin-left: 311px;" id="nu">150</div>
<div style="clear: both;"></div>
JS
/*字数限制*/
$("#editor_content").on("input propertychange", function () {
var $this = $(this),
_val = $this.val(),
count = "";
if (_val.length > 150) {
$this.val(_val.substring(0, 150));
}
count = 150 - $this.val().length;
});
$(function(){
upLoadWidth()//控制图片的大小
$(window).resize(function(){
upLoadWidth()
})
myInputChange('.copyTi','.remainingNumbers','50','input')//实时监控input的字数变化
myInputChange('.copyCon','#nu','150','textarea')//实时监控textarea的字数变化
uploadImg()//控制内容区域字数的变化
});
参考了https://blog.csdn.net/six365/article/details/78982900博客的字数限制,结合显示字符串功能,有问题的可以留言哦。