简体   繁体   English

html 输入与 javascript。 添加

[英]html input with javascript . adding

When the date of birth is entered in my input, I want a full stop after 2 characters are entered automatically.在我的输入中输入出生日期时,我希望在自动输入 2 个字符后使用句号。 I know it's done with toLocaleLowerCase我知道它是用 toLocaleLowerCase 完成的

Sample: 01011980样品:01011980

Output: 01.01.1980 Output:01.01.1980

If the sample is always fixed length which I guess it is, you can do it like this:如果样本总是固定长度,我猜是这样,你可以这样做:

var sample = '01011980';

function processString(inputString){
    return inputString.substr(0,2)+'.'+inputString.substr(2,2)+'.'+inputString.substr(4,4);
    
}

output = processString(sample);

alert(output);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM