使用美国日期输入日期时间的 jQuery 输入掩码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21396352/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery Input Masks for datetime input using American dates
提问by pbarney
I'm using Robin Herbot's excellent jQuery Input Masks plugin. [ https://github.com/RobinHerbots/jquery.inputmask]. It's quite complete and seems to have everything I need, but I can't seem to figure one thing out.
我正在使用 Robin Herbot 出色的 jQuery Input Masks 插件。[ https://github.com/RobinHerbots/jquery.inputmask]。它非常完整,似乎拥有我需要的一切,但我似乎无法弄清楚一件事。
How do I create a mask like: "mm/dd/yyyy hh:mm pm"where both the date portion and the time portion work like the "date" and "time" masks work?
如何创建像“mm/dd/yyyy hh:mm pm”这样的掩码,其中日期部分和时间部分都像“日期”和“时间”掩码一样工作?
I can use date or time, but datetime uses the European dd/mm format rather than the mm/dd format I need. I've tried several permutations, but I'm clearly missing something and the documentation takes a lot for granted.
我可以使用日期或时间,但日期时间使用欧洲 dd/mm 格式而不是我需要的 mm/dd 格式。我已经尝试了几种排列,但我显然遗漏了一些东西,而且文档认为很多都是理所当然的。
回答by Bob
$('#InputID').inputmask({
mask: "2/1/y h:s t\m",
placeholder: "mm/dd/yyyy hh:mm xm",
alias: "datetime",
hourFormat: "12"
});
Check other aliases.
检查其他别名。
回答by user2687646
Go here: http://digitalbush.com/projects/masked-input-plugin/
去这里:http: //digitalbush.com/projects/masked-input-plugin/
Use this:
用这个:
$('#InputID').mask("99/99/9999 99:99 aa");
You're welcome.
别客气。
回答by Dunadan
Maskedinputplugin is the best solution for datetime type input - simply and lightweight.
Maskedinput插件是日期时间类型输入的最佳解决方案 - 简单轻便。
As for "accepting ANY digit": you can easy modificate base js library regex by adding your own rules:
至于“接受任何数字”:您可以通过添加自己的规则轻松修改基础js库正则表达式:
{ definitions: { 9: "[0-9]", 1: "[0-1]", 2: "[0-2]", a: "[A-Za-z]", "*": "[A-Za-z0-9]" }
{ definitions: { 9: "[0-9]", 1: "[0-1]", 2: "[0-2]", a: "[A-Za-z]", "*": "[A-Za-z0-9]" }