Pikaday 选择 2018 尽管 yearRange 集是 [1968,

Pikaday selecting 2018 even though the yearRange set is [1968, 2005]

如何在 select 框中将 2005 select 设置为默认年份。

$(function () {
    var field = $('#calendar')[0];
    

    var pika = new Pikaday({
        field: field,
        yearRange: [1968, 2005],
        onSelect: function () {
            console.log('selected');
        },
        onOpen: function () {
            console.log('open');
        },

        onClose: function () {
            console.log('closed');
        }
    });

});
<link href="https://rawgit.com/dbushell/Pikaday/master/css/pikaday.css" rel="stylesheet"/>
<script src="https://rawgit.com/dbushell/Pikaday/master/pikaday.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>2018 year is selcted even though year range is [1968, 2005]</h1>
<input id="calendar" type="text" value=""></input>

尝试在打开时设置为 2005:

onOpen: function () {
    this.gotoYear(2005);
},

http://jsfiddle.net/ms97uved/

使用代码段中显示的 defaultDate。 defaultDate 会将日历设置为给定日期。 setDefaultDate 将选择并突出显示给定的日期。

$(function () {
    var field = $('#calendar')[0];
    var date = new Date(2005,0,1);

    var pika = new Pikaday({
        field: field,
        defaultDate:date,
        setDefaultDate: date,
        yearRange: [1968, 2005],
        onSelect: function () {
            console.log('selected');
        },
        onOpen: function () {
            console.log('open');
        },

        onClose: function () {
            console.log('closed');
        }
    });

});
<link href="https://rawgit.com/dbushell/Pikaday/master/css/pikaday.css" rel="stylesheet"/>
<script src="https://rawgit.com/dbushell/Pikaday/master/pikaday.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1>2018 year is selcted even though year range is [1968, 2005]</h1>
<input id="calendar" type="text" value=""></input>