墨染丶

导航

textarea 文本框 实现右下角展现 动态字数

文本框CSS

.textarea-style{
border:1px solid #000001;
border-radius:5pt;
height:60pt;
font-size:10pt;
margin-bottom: 2vh;
width:100%;
color: #000001;
overflow-x:hidden;
text-indent:20px
}

HTML
<textarea id="handledMsg" maxlength="200" cols="70" rows="5" class="textarea-style"
placeholder="请输入处理方法,不超过200字" onkeyup="setLength(this,200,'wordsLength');"></textarea>
<span id="wordsLength" style="position:absolute; right:5px; bottom:3vh;font-size:12px; color:#BDCADA">0/200</span>

JS
function setLength(obj,maxlength,id){
var num=maxlength-obj.value.length;
var leng=id;
if(num<0){
num=0;
}
document.getElementById(leng).innerHTML=num+"/200";
}
 

posted on 2020-01-07 13:11  墨染丶  阅读(4440)  评论(0编辑  收藏  举报