Jquery datepicker在特定年份范围之后从列表中选择第一年 [英] Jquery datepicker selects first year from list after certain year range

查看:86
本文介绍了Jquery datepicker在特定年份范围之后从列表中选择第一年的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$('.DateOfBirth').datepicker({
           changeMonth: true,
           changeYear: true,
           dateFormat: 'dd/mm/yy',
           defaultDate: new Date(),
         yearRange: "-100:+0"

       });





上面的代码列出了年份范围:2017年至1917年的日期选择器下拉列表。



现在当我选择一年说2000时,下拉菜单将年份值设置为2000,这是正确的,它可以正常工作到2000年,但如果我在2000年之前选择一年说1999年等下拉列表显示第一年,即下拉选择中的1917年,但如果我选择日期,则填写所选年份1999日期,例如23/08/1999,这是正确的,但下拉列表仍显示1917.



注意:具有上述类和上述代码的文本框位于视图上显示的局部视图中。



月份下拉工作完美,它只是下降创建问题的一年。我也删除了yearRannge属性并尝试了它仍然无法正常工作。

如果yearRange = -100:+ 0所以如果我选择2000年之前的任何年份选择1917

如果yearRange = -100:+100所以如果我选择1950它选择2050年,如果1970年它选择2070等等。



我尝试过:



我尝试调用onselect函数,但对我没有用。



The above code brings a list of years ranging : 2017 to 1917 in the year dropdown of datepicker.

Now when i select a year say 2000 the dropdown sets the year value to 2000 which is correct and it works fine till 2000 but if i select a year before 2000 say 1999 etc the dropdown displays the first year i.e 1917 in dropdown selection, but if i select the date it populates the selected year 1999 date eg 23/08/1999 which is correct but the dropdown still has 1917 displayed on it.

Note : the textbox having the above class and the above code is in a partial view which is displayed on a View.

The month dropdown works perfectly, its just the year dropdown creating problem. Also i removed yearRannge attribute and tried still it doesnt work.
if yearRange = -100:+0 so 1917 is selected if i choose any year before 2000
if yearRange = -100:+100 so if i select 1950 it selects 2050 , if 1970 it selects 2070 and so on.

What I have tried:

I tried calling onselect functions but didnt work for me.

推荐答案

('。DateOfBirth')。datepicker({
changeMonth:true ,
changeYear:true,
dateFormat:'dd / mm / yy',
defaultDate:new Date(),
yearRange: - 100:+0

});
('.DateOfBirth').datepicker({ changeMonth: true, changeYear: true, dateFormat: 'dd/mm/yy', defaultDate: new Date(), yearRange: "-100:+0" });





上面的代码列出了年份范围:2017年至1917年的日期选择器下拉列表。



现在当我选择一年说2000时,下拉菜单将年份值设置为2000,这是正确的,它可以正常工作到2000年,但如果我在2000年之前选择一年说1999年等下拉列表显示第一年,即下拉选择中的1917年,但如果我选择日期,则填写所选年份1999日期,例如23/08/1999,这是正确的,但下拉列表仍显示1917.



注意:具有上述类和上述代码的文本框位于视图上显示的局部视图中。



月份下拉工作完美,它只是下降创建问题的一年。我也删除了yearRannge属性并尝试了它仍然无法正常工作。

如果yearRange = -100:+ 0所以如果我选择2000年之前的任何年份选择1917

如果yearRange = -100:+100所以如果我选择1950它选择2050年,如果1970年它选择2070等等。



我尝试过:



我尝试调用onselect函数,但对我没用。



The above code brings a list of years ranging : 2017 to 1917 in the year dropdown of datepicker.

Now when i select a year say 2000 the dropdown sets the year value to 2000 which is correct and it works fine till 2000 but if i select a year before 2000 say 1999 etc the dropdown displays the first year i.e 1917 in dropdown selection, but if i select the date it populates the selected year 1999 date eg 23/08/1999 which is correct but the dropdown still has 1917 displayed on it.

Note : the textbox having the above class and the above code is in a partial view which is displayed on a View.

The month dropdown works perfectly, its just the year dropdown creating problem. Also i removed yearRannge attribute and tried still it doesnt work.
if yearRange = -100:+0 so 1917 is selected if i choose any year before 2000
if yearRange = -100:+100 so if i select 1950 it selects 2050 , if 1970 it selects 2070 and so on.

What I have tried:

I tried calling onselect functions but didnt work for me.


更新jquery。这是我发现的唯一解决方案。感谢Karthik。
Update jquery. This is the only solution i found for this issue. Thanks to Karthik.


这篇关于Jquery datepicker在特定年份范围之后从列表中选择第一年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆