简体   繁体   English

我可以使用 Jquery UI 日期选择器来更改键盘输入日期的格式吗?

[英]Can I use Jquery UI datepicker to change format of a keyboard-entered date?

The Norwegian date format is dd.mm.yyyy.挪威日期格式为 dd.mm.yyyy。 I've changed the datepicker dateformat to this, no problem.我已经将日期选择器的日期格式更改为此,没问题。 However, if a user decides to enter a date by keyboard, they might for instance enter 3.4.12, or even just 3.4.但是,如果用户决定通过键盘输入日期,他们可能会输入 3.4.12,或者甚至只是 3.4。 I would like the datepicker to format the dates correctly on blur, even if the date was entered by keyboard and not by choosing from the datepicker.我希望日期选择器在模糊时正确设置日期格式,即使日期是通过键盘输入的,而不是通过从日期选择器中选择的。 I've tried the following, but it didn't work:我尝试了以下方法,但没有用:

$('.dp').datepicker({
   onClose: function(dateText, inst) {
      $(this).val(dateText)
   }
})

Nothing happens to the input, because the dateText returned is identical to the entered value.输入没有任何变化,因为返回的日期文本与输入的值相同。

This should get you going in the right direction.应该让你朝着正确的方向前进。 It's been tested in Chrome and works as you expect.它已经在 Chrome 中进行了测试,可以正常工作。

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

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