简体   繁体   English

jQuery datepicker年份范围

[英]Jquery datepicker year range

I use jquery date picker plugin in my asp.net website. 我在asp.net网站上使用jquery日期选择器插件。 I set the default Date to 1900-01-01 and year range to year Range to 1900:2020. 我将默认的日期设置为1900-01-01,将年份范围设置为年份范围为1900:2020。 The problem is when I select a date from picker and it will appear the date in text box. 问题是当我从选择器中选择一个日期时,该日期将出现在文本框中。 This is fine. 这可以。 But, when I select the year again, the starting year already remove those year less than what I had selected just now. 但是,当我再次选择年份时,起始年份已经比我刚刚选择的年份少了一年。 Example: If I select 2000-01-01 and select the year again, it will show year greater than 2000 only. 示例:如果我选择2000-01-01并再次选择年份,它将只显示大于2000的年份。 Why like this, I think is asp.net issue because I have tried in Jsfiddle run the javascript and is working. 为什么这样,我认为是asp.net问题,因为我在Jsfiddle中尝试过运行javascript并能正常工作。

  $(function() { var today = new Date(); var year = today.getFullYear(); $( "#<%=txtDOB.ClientID %>" ).attr('readonly', 'true'); $( "#<%=txtDOB.ClientID %>" ).datepicker({ defaultDate: "1900-01-01", changeMonth: true, changeYear: true, yearRange: '1900:' + "'" + year + "'" , maxDate: today, numberOfMonths: 1, dateFormat: "dd/M/yy", onClose: function( selectedDate ) { $( "#<%=txtDOB.ClientID %>" ).datepicker( "option", "minDate", selectedDate ); } }); }); 

I wonder if this thing over here is creating problem. 我想知道这件事是否正在造成问题。

$( "#<%=txtDOB.ClientID %>" ).datepicker( "option", "minDate", selectedDate );

Try changing it to 尝试将其更改为

$( "#<%=txtDOB.ClientID %>" ).datepicker( "option", "defaultDate", selectedDate );

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

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