使用 jQuery DatePicker &一个 jQuery Mask,在单个输入上具有 4 年日期
我们有一个文本框,我们希望它既能触发 jQuery UI 日期选择器,又能在文本框中徒手输入文本。我们目前正在通过 jQuery UI Mask 和 jQuery UI Mask 来实现这一目标。同一文本框上的 DatePicker。但是,我必须“破解”掩码才能使其正常工作 - 因为,一旦您自由文本输入: 04/29/19
然后,在您完成输入“83”以完成四位数日期之前,日期选择器会触发一些事件它将日期选择器的当前日期移动到您输入的日期,但是,它也会删除到目前为止的整个日期。所以目标是输入日期:04/29/1983,但日期选择器删除了我到目前为止的内容。起初我们认为面具有问题,但现在我只需要弄清楚如何杀死日期选择器事件以免错误触发。任何帮助将不胜感激!
抱歉,代码示例:
$('#txbxSocialHistoryDate').datepicker({
showButtonPanel: true,
changeMonth: true,
changeYear: true
});
$('#txbxSocialHistoryDate').mask("99/99/9999", { placeholder: " " });
We have a textbox that we want to both trigger a jQuery UI datepicker, as well as have the ability to enter text freehand into the textbox. We are currently achieving this is with both jQuery UI Mask & DatePicker on the same textbox. However, I had to 'hack' the mask to get it to work - because, once you freetext enter: 04/29/19
Then, before you can finish entering the "83" to finish the four digit date, datepicker fires some event that moves the datepicker's current date to the one you are entering, but, it also deletes the entire date so far. So the goal was to enter the date: 04/29/1983, but the datepicker deleted what I had so far. At first we thought the mask was at fault, but now I just need to figure out how to kill the datepicker event from firing mistakenly. Any help would be so appreciated!
Sorry, code sample:
$('#txbxSocialHistoryDate').datepicker({
showButtonPanel: true,
changeMonth: true,
changeYear: true
});
$('#txbxSocialHistoryDate').mask("99/99/9999", { placeholder: " " });
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我遇到了同样的问题,但这不是 JQuery datepicker 问题,问题是 MASK 插件,当您写入年份的 2 或 4 位数字时,jquery 会触发事件,但是当事件被触发时,MASK 事件也会被调用,并且会发生冲突。
解决方案是包含掩码的 JQuery 日期选择器。
我使用触发按钮解决了我的问题,因为如果用户想要写日期,他只需输入日期即可,但是,如果他们想要选择,只需单击按钮触发器即可。
尝试一下。
http://jqueryui.com/demos/datepicker/#icon-trigger
I had the same problem, but it's not a JQuery datepicker problem, the problem is MASK plugin, jquery fires the event when you write 2 or 4 digits for year, but when event is fired the MASK event is called too, and the conflict occur.
The solution would be a JQuery datepicker with mask included.
I solved my problem using trigger button, because if the user wants do write de date he just type the date and ok, but, if they want the selection just click on button trigger.
try it.
http://jqueryui.com/demos/datepicker/#icon-trigger
上面的答案绝对适用于这个问题。但是,在没有触发按钮的情况下,我想出了一个解决方案,如下所示:
那么我做了什么:
这个最初的错误让我找到了答案。
The above answer definitely works for this question. However, without a trigger button, I came up with a solution, as follows:
So what I did:
This initial mistake led me to the answer.