Javascript 12 小时时间格式的 JQuery 输入掩码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34645903/
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 mask for 12 hour time format
提问by Lance Shi
I am using the jquery inputMask library(https://github.com/RobinHerbots/jquery.inputmask). But feel free to let me know if there is a better inputMask library. But I need inputMask, not a time picker.
我正在使用 jquery inputMask 库(https://github.com/RobinHerbots/jquery.inputmask)。但是如果有更好的 inputMask 库,请随时告诉我。但我需要 inputMask,而不是时间选择器。
The scenario is to have inputMask on the time field. We want to display and have inputMask based on user's locale so it should support both 12 hour and 24 hour format. Originally we only supported 24 hour format so the mask code looks like this:
场景是在时间字段上有 inputMask。我们希望根据用户的语言环境显示并拥有 inputMask,因此它应该支持 12 小时和 24 小时格式。最初我们只支持 24 小时格式,所以掩码代码如下所示:
$('input[id$="endTime"]').inputmask("hh:mm:ss", {placeholder: "HH:MM:SS", insertMode: false, showMaskOnHover: false});
Please be aware that we need to support seconds as well. For 12 hour format, I have actually tried several formats but none of them worked well for me. So is it possible to mask that?
请注意,我们也需要支持秒。对于 12 小时格式,我实际上尝试了几种格式,但没有一种对我来说效果很好。那么有可能屏蔽吗?
回答by Vuong
$('input[id$="endTime"]').inputmask("hh:mm:ss", {
placeholder: "HH:MM:SS",
insertMode: false,
showMaskOnHover: false,
hourFormat: 12
}
);
Tips: Open file jquery.inputmask.bundle.js
, search datetime
and review all options for it.
提示:打开文件jquery.inputmask.bundle.js
,搜索datetime
并查看它的所有选项。
(Sorry, i can't add comment because i do not have enough limit point to do it.)
(对不起,我不能添加评论,因为我没有足够的限制点来做。)
回答by hamidsolat
put "24" not 24
把“24”而不是24
$('input[id$="endTime"]').inputmask("hh:mm:ss", {
placeholder: "HH:MM:SS",
insertMode: false,
showMaskOnHover: false,
hourFormat: "24"
});