<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no">
<script>document.documentElement.style.fontSize = (window.innerWidth/10.8).toFixed(2) + 'px';</script>
</head>
<style>
*{
margin:0;
padding: 0;
}
p{
max-width: 6.19rem;
height: .5rem;
line-height: .5rem;
color: #666;
font-size: .4rem;
font-weight: 400;
overflow: hidden;
}
</style>
<body>
<p id="user"></p>
</body>
</html>
<script src='https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js'></script>
<script>
var formatUser =function(userName){
String.prototype.gblen = function() {
var len = 0;
for (var i=0; i<this.length; i++) {
if (this.charCodeAt(i)>127 || this.charCodeAt(i)==94) {
len += 2;
} else {
len ++;
}
}
return len;
}
if(userName.gblen()>30 && userName.indexOf('@')!=-1){
var first = userName.substring(0,10);
var num = userName.lastIndexOf('@');
var last = userName.substring(num,userName.length);
userName= first+"......"+last;
}
return userName;
}
//$('#user').html(formatUser('3757761201EB51636BC61E99DBCF69BF@qq.sohu.com'))//3757761201......@qq.sohu.com
//$('#user').html(formatUser('愛學習的小青蛙'))//愛學習的小青蛙
//$('#user').html(formatUser('qqhuan123.'))//qqhuan123.
$('#user').html(formatUser('o9t2luIQEIaDJZOYB1iUGLOCfu6w@weixin.sohu.com '))//o9t2luIQEI......@weixin.sohu.com
//$('#user').html(formatUser('愛學習的小青蛙愛學習的小青蛙愛學習的小青蛙愛學習的小青蛙'))//愛學習的小青蛙愛學習的小青蛙愛
</script>