转载地址 https://www.cnblogs.com/lr393993507/p/5841655.html
<
html
>
<
body
>
<
script
type=
"text/javascript"
>
var
idCard =
'412721111100005555';
function
plusXing(
str,
frontLen,
endLen) {
var
len =
str.
length -
frontLen -
endLen;
var
xing =
'';
for (
var
i =
0;
i <
len;
i++) {
xing +=
'*';
}
return
str.
substring(
0,
frontLen) +
xing +
str.
substring(
str.
length -
endLen);
}
// 这三个参数的含义:str:字符串,frontLen:前面保留位数,endLen:后面保留位数。
var
a =
plusXing(
idCard,
3,
4)
console.
log(
a)
// 412***********5555
<
/
script
>
</
body
>
</
html
>