问题
I want to replace alternate 2 digit of a number with a dot in polymer 3. I tried something but it is not working as i wanted. Please help.
before masking : 56789012 after masking : 5..8..1.
回答1:
Here you go have fun with it:
var maskingfield = function (str) {
var out = "";
for (var j = 0; j < str.length; j++) {
if (j % 3 === 1 || j % 3 === 2) {
out += '.';
} else {
out += str[j];
}
}
return out;
}
Calling : maskingfield("56789012")
will give you "5..8..1."
来源:https://stackoverflow.com/questions/56747620/replacing-alternate-2-digits-of-a-number-with-dot-in-polymer-3