获取字符串的长度:
let str=‘fgkljfkd的规范你们’
let reg=str.replace(/[^x00-xff]/g,"01").length
console.log(reg)
【拓展应用】文字长度超过多长时鼠标悬浮显示提示
HTML:
<span :title="getBLen(str).length>8?str:' ' " class="title">和银行股份</span>
data:{
return:{str:'这是一个很长的字符串~~~~~~~~~~~~~~'}
}
JS:
getBLen(str) {
if (str == null) return 0;
if (typeof str != "string"){
str += "";
}
return str.replace(/[^x00-xff]/g,"01").length;
},
CSS:
.title{
overflow:hidden;
white-space:nowrap;
text-overflow:ellipsis;
}