layui textarea 文本长度限制及样式分享

分享 未结 1 142
观海听潮
观海听潮 2019-9-11
悬赏:20飞吻
css样式:

.layui-input-block {
position: relative;
}

.word {
position: absolute;
right: 10px;
bottom: 10px;
color: #aaa;
font-size: 12px;
}
HTML:

<div class="layui-form-item">
<label class="layui-form-label layui-required">消息简介:</label>
<div class="layui-input-block">
<textarea placeholder="请输入消息简介" oninput="wordLeg(this);" maxlength="100" onpropertychange="if(value.length>100) value=value.substr(0,100)" name="desc" class="layui-textarea"></textarea>
<div class="word"><span class="text_count">0</span> / <span class="num_count" id="numCount">100</span></div>
</div>
</div>
JS 部分:

//字数限制
window.wordLeg = function (obj) {
var currleg = $(obj).val().length;
var length = $(obj).attr('maxlength');
if (currleg > length) {
layer.msg('字数请在' + length + '字以内');
} else {
$('.text_count').text(currleg);
}
}

示例效果:

回帖