定义的div
<div>
<textarea name="content" class="layui-textarea" id="area" maxlength="50"
placeholder="输入5-50个字符" onkeyup="javascript:texLength(this, 50, 'textarea_length');"
style="height: 100px;width: 81%;"></textarea>
<span class="red" id="textarea_length">0</span> / <span class="num_count">50</span>
</div>
function方法
function texLength(obj, maxlength, id) {
var curr = obj.value.length;
if (curr > maxlength) {
layer.msg('字数在' + maxlength + '字以内');
} else {
document.getElementById(id).innerHTML = curr;
}
}