jquery datepicker未显示yearRange

时间:2012-04-27 15:15:02

标签: javascript jquery datepicker

我使用jQuery datepicker,需要一个带有年份选择元素。这是我元素的代码:

$("#geburtsdatum").datepicker({
    "yearRange":"2000:2010",
    "firstDay":1,
    "dayNamesMin":["So","Mo","Di","Mi","Do","Fr","Sa"],
    "monthNames":["Januar","Februar","März","April","Mai","Juni","Juli","August","September","Oktober","November","Dezember"],
    "dateFormat":"dd.mm.yy"});

但是我错过了我的日期选择器中的选择。有谁知道我做错了什么? (我正在使用jquery-1.7.1。)

my datepicker

3 个答案:

答案 0 :(得分:3)

您需要添加“changeYear”选项。 See the source on the documentations page here.

答案 1 :(得分:2)

您的代码应该是

$("#geburtsdatum").datepicker({
yearRange: "2000:2010",
firstDay: 1,
dayNamesMin: ["So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"],
monthNames: ["Januar", "Februar", "März", "April", "Mai", "Juni", "Juli", "August", "September", "Oktober", "November", "Dezember"],
dateFormat: "dd.mm.yy",
changeYear: true
});​

这是一个有用的小提琴:http://jsfiddle.net/pratik136/WByxq/

答案 2 :(得分:1)

我就是这样做的:

$(".datefield").datepicker({
    minDate: (new Date(1920, 0, 1)),
    maxDate: "+100Y",
    yearRange: '1920:2020',
    changeMonth: true,
    changeYear: true,
    onSelect: function() { $(this).valid(); }
});