jQuery datepicker年下拉列表从1900开始,我希望它从底部开始 [英] jQuery datepicker year dropdown starts from 1900 and I want it to start from the bottom

查看:138
本文介绍了jQuery datepicker年下拉列表从1900开始,我希望它从底部开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  $(#datepicker)我在我的网站上使用jQuery datepicker, .datepicker(
{
dateFormat:'mm / dd / yy',
changeMonth:true,
changeYear:true,
yearRange:1900:-13
}
).on('change',function(){
$(this).valid(); //触发验证测试
//'$ )'是指'$(#datepicker)'
});

所以我的年选择栏可以使1900年到2004年。



默认情况下,打开年份选择框 - 它从1900开始,我必须滚动很多更相关的一年。



如何设置我的jQuery datepicker从2004开始(向上滚动)而不是从1900(向下滚动)



研究此问题导致旧帖(7年前),我可能可以找到一个更实用的解决方案,适用于这些天。

解决方案

这是我如何解决我的问题。
,我认为这就是为什么jQuery没有修复这个Bug,因为有一种方法可以从最后一个日期开始:

  dateFormat:'mm / dd / yy',
changeMonth:true,
changeYear:true,
yearRange:-70:,
maxDate:-13Y

与我在这里发布的原始代码相比, code> yearRange 作为固定年份 yearRange:1900:-13
最好从下到上使用这个: - 70:。并设置 maxDate
所以现在我从2004年开始,而不是1900年,我的年选择框。



希望这有助于其他人。



PS:所有其他解决方案都已经过测试。他们非常缓慢,有些人工作不好(特别是老年人,例如今年,而不是2004年)。


I am using jQuery datepicker on my website and I have it set like this:

$( "#datepicker" ).datepicker( 
    { 
        dateFormat: 'mm/dd/yy',  
        changeMonth: true, 
        changeYear: true,  
        yearRange: "1900:-13" 
    } 
).on('change', function() {
    $(this).valid();  // triggers the validation test
    // '$(this)' refers to '$("#datepicker")'
}); 

So my year select bar enables years 1900 and up to 2004.

By default when opening the year selectbox - it starts from 1900 and I have to scroll a lot for a more relevant year.

How can I set my jQuery datepicker to start from 2004 (scrolling up) and not from 1900 (scrolling a lot down)?

Researching this issue leads to old posts (7 years ago) and I might be able to find a more practical solution that works for these days.

解决方案

This is how I solved my problem. and I think this is why jQuery aren't fixing this "Bug" because there is a "way" to get the year started from the last date:

dateFormat: 'mm/dd/yy',
changeMonth: true, 
changeYear: true,  
yearRange: "-70:", 
maxDate: "-13Y"

In comparison to my original code posted here, instead if using yearRange as fixed years yearRange: "1900:-13" it's better to use this from bottom up: "-70:". and set the maxDate. So now I get my year select box starting from 2004 and not 1900.

Hope this helps others out there.

P.S: All the other solutions have been tested. They are very slow, and some don't work so well (especially the old ones - sets current year instead of 2004 for example).

这篇关于jQuery datepicker年下拉列表从1900开始,我希望它从底部开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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