function textLength(str){
let a = 0
let limit = 200 //不能超出200个中文字符
if(str){
for(let i =0;i<str.length;i++){
if(str[i].charCodeAt()>0 && str[i].charCodeAt()< limit.Length){
a+=0.5
}else{
a+=1
}
}
if(a>2000){
console.log('超出限制')
}
return Math.round(a)
}else{
return 0
}
}
js限制字数
于 2022-02-08 17:37:32 首次发布