简体   繁体   English

生日输入字段-在特定数量的字符后自动添加点

[英]Birthday input field - auto-adding dots after specific amount of characters

Hey guys, unusual question: I have a input field #birthday that should accept european date format like this. 嗨,大家好,一个不寻常的问题:我有一个输入字段#birthday,应该接受这样的欧洲日期格式。 dd.MM.yyyy dd.MM.yyyy

I wonder if it is possible to auto apply dots when typed into this field. 我想知道是否可以在键入此字段时自动应用点。

Imagine the inputfield is focused and empty. 想象一下,输入字段已聚焦且为空。 I start typing to numbers and the field autogenerates a dot, again two numbers and a dot is generated. 我开始输入数字,然后该字段自动生成一个点,再次生成两个数字并生成一个点。

My aim is to type only numbers without needing to add the dots. 我的目的是只键入数字而无需添加点。

any idea how i could achieve that with jquery or javascript in general? 任何想法,我怎么能用一般的jQuery或javascript实现呢?

$('#birhtday').keypress(function() {
    // ?
})

Why not use existing jQuery plugins? 为什么不使用现有的jQuery插件?

  • Masked input 屏蔽输入
  • meioMask - I find it nicer because it doesn't use those underscores (but it seems to have some bugs when TAB ing through filled form) meioMask-我发现它更好,因为它不使用那些下划线(但TAB填充表单时似乎存在一些错误)

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

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