jQuery DatePicker:当日期字段为12-31-9999时,currentDate不起作用 [英] jQuery DatePicker: currentDate does not work when the date field is 12-31-9999
问题描述
当当前字段值均为12-31-9999且yearRange为2000:+1时,DatePicker无法正确处理currentDate的计算.当我单击该字段以打开DatePicker时,currentDate的结果变为1-1-2000.因此,似乎DatePicker将日期包装到yearRange的开始.但是,如果我删除yearRange,则DatePicker的默认范围为-10:+10,这将导致年份为9989:10009.
当我单击包含12-31-9999的字段时,我更希望DatePicker显示今天的日期.注意:逃离现场时,请勿进行任何更改.这可能吗?
$(".datePicker").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "yy-mm-dd",
yearRange: 2000:+1
});
您看到的问题是因为输入字段中的日期("9999-12-31")超出了您指定的范围("2000:+1).该范围产生的日期为2000-2019年(根据规范,结束年份是今天的年份加1).
您还说过但是,如果我删除yearRange,则DatePicker的默认范围是-10:+10".不完全的.默认值为"c-10:c + 10",如果您查看规格,它不是完全一样的东西-"c"表示它将范围输入范围定为10年+/-年,与之相反到今天.
我认为这种误解导致了您的错误.如果要显示9999日期,则将年份范围设置为
yearRange: "2000:c+1"
这会将最大年份设置为输入年份+1,而不是今天的年份+1.
有关演示,请参见 http://jsfiddle.net/5ornc4gv/7/. /p>
http://api.jqueryui.com/datepicker/#option-yearRange包含格式字符串的详细信息.
但是,正如我在评论中指出的那样,如果您的软件使用NULL表示没有实际定义结束日期的时间段的结束日期",那么这将是一个较小的问题.而且,由您年份范围产生的日期选择器中的年份下拉列表很难使用,并且由于其中的数据量大,在某些浏览器中可能会造成一些滞后.
The DatePicker does not properly handle the calculation of the currentDate when both the current field value is 12-31-9999 and the yearRange is 2000:+1. The result for the currentDate becomes 1-1-2000 when I click on the field to open DatePicker. So, it appears that DatePicker wraps the date around to the start of the yearRange. But, if I remove the yearRange, then DatePicker defaults to a range of -10:+10, which results in the year being 9989:10009.
I would much rather have the DatePicker show today's date when I click on the field that contains 12-31-9999. Note: no change should be made when escaping out of the field. Is this possible?
$(".datePicker").datepicker({
changeMonth: true,
changeYear: true,
dateFormat: "yy-mm-dd",
yearRange: 2000:+1
});
The problem you're seeing is because the date in your input field ("9999-12-31") is outside the range you've specified ("2000:+1"). This range produces dates from 2000-2019 (the end year is today's year plus one, as per the spec).
Also you said "But, if I remove the yearRange, then DatePicker defaults to a range of -10:+10". Not quite. It defaults to "c-10:c+10" which if you look at the spec, is not quite the same thing - the "c" means it places the range at 10 years +/- the year in the input, as opposed to today's year.
I think this misunderstanding has led to your mistake. If you want it to display the 9999 date then set the year range to
yearRange: "2000:c+1"
This will set the max year as the input year +1, as opposed to today's year +1.
See http://jsfiddle.net/5ornc4gv/7/ for a demo.
http://api.jqueryui.com/datepicker/#option-yearRange contains details of the format string.
As I remarked in the comments though, this would be a less of an issue if your software used NULL to represent the "end date" of periods of time with no realistic define end date. Also the year drop-down-list in the datepicker which produced by your year range is hard to use and might cause a bit of a lag in some browsers due to the amount of data in it.
这篇关于jQuery DatePicker:当日期字段为12-31-9999时,currentDate不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!