码迷,mamicode.com
首页 > 其他好文 > 详细

字符串除了第一位和最后一位中间用*替换

时间:2017-05-23 13:16:33      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:trim   字符   username   --   while   字符串   function   this   str   

$(".user-name").each(function(){
var userName = $(this).html().trim();
var _name = "";
var nameLength = userName.length;
if (nameLength > 2) {
var nameLength = nameLength - 2;
while (nameLength > 0) {
_name += "*";
nameLength--;
}
userName = userName.substr(0, 1) + _name + userName.substr(userName.length - 1, userName.length);
$(this).html(userName);
}
})

字符串除了第一位和最后一位中间用*替换

标签:trim   字符   username   --   while   字符串   function   this   str   

原文地址:http://www.cnblogs.com/qhhw/p/6893373.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!