[英]jQuery Datepicker today button does not put today's date in the input box
[英]Why does jQuery Datepicker select today's date when numbers are entered and enter is pressed?
我在我正在处理的应用程序中发现了一个场景,该场景已复制到jQuery网站上。 例如,如果您在此处输入一个整数字符串(例如“ 12345678”)并按Enter,您将看到当前日期将填入输入。 然后,如果您再次键入另一个数字字符串并再次按Enter键,则您键入的字符串仍将保留。
在我的应用程序中,我需要键入任何数字以在ANY输入按键后保留。 我的问题是:
Enter键将始终获取选定的日期,并将此值输出到文本框。 此选定日期将是打开时的默认日期。 您可以在打开日期选择器时设置defaultDate,但它可以是有效日期或今天的日期。 当前无法打开没有defaultDate的日期选择器。
通常,您可以通过将所选日期设置为null来删除所选日期。
$('#mydate').datepicker('setDate', null);
但这在初始打开日期选择器时将不起作用,因为它总是以默认/选定的日期打开。
我想出了一个小提琴,说明可能的解决方法 。
/***
Since there is ALWAYS a default date in the datepicker when it's opened,
then let's try and trigger an event after it has been opened, then set the
date to null.
***/
$('#textbox').datepicker(
{
beforeShow: function()
{
$(this).trigger('afterShow');
}
})
.bind('afterShow', function()
{
var $this = $(this);
setTimeout(function()
{
$this.datepicker('setDate', null);
}, 100);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.