多个日期选择器 – 跳月问题

我使用jquery多个datepicker日历。 当我去四月份点击日期时,日期选择器会恢复到三月。

var lastMDPupdate = '2012-03-28'; $(function() { // Version // //$('title').append(' v' + latestMDPver); $('.mdp-version').text('v' + latestMDPver); $('#mdp-title').attr('title', 'last update: ' + lastMDPupdate); // Documentation // $('i:contains(type)').attr('title', '[Optional] accepted values are: "allowed" [default]; "disabled".'); $('i:contains(format)').attr('title', '[Optional] accepted values are: "string" [default]; "object".'); $('#how-to h4').each(function () { var a = $(this).closest('li').attr('id'); $(this).wrap(''); }); $('#demos .demo').each(function () { var id = $(this).find('.box').attr('id') + '-demo'; $(this).attr('id', id) .find('h3').wrapInner(''); }); // Run Demos $('.demo .code').each(function() { eval($(this).attr('title','NEW: edit this code and test it!').text()); this.contentEditable = true; }).focus(function() { if(!$(this).next().hasClass('test')) $(this) .after('') .next('.test').click(function() { $(this).closest('.demo').find('.box').removeClass('hasDatepicker').empty(); eval($(this).prev().text()); $(this).remove(); }); 

Js小提琴链接添加。 http://jsfiddle.net/bJ7zj/#update

提前致谢

问题似乎是jQuery UI违约到今天的日期,因为它无法解析几个日期。 如果您不想在日期中使用或计划更新的jQuery UI,您可以使用以下fixhack添加dates = dates.split(',').pop() ,允许解析器解析最后一个日期显示控件时列出。 您可以在jQuery UI引用之后将此代码放在任何位置

 $.datepicker._setDateFromField= function (inst, noDefault) { if (inst.input.val() == inst.lastVal) { return; } var dateFormat = this._get(inst, 'dateFormat'); var dates = inst.lastVal = inst.input ? inst.input.val() : null; dates = dates.split(',').pop() var date, defaultDate; date = defaultDate = this._getDefaultDate(inst); var settings = this._getFormatConfig(inst); try { date = this.parseDate(dateFormat, dates, settings) || defaultDate; } catch (event) { this.log(event); dates = (noDefault ? '' : dates); } inst.selectedDay = date.getDate(); inst.drawMonth = inst.selectedMonth = date.getMonth(); inst.drawYear = inst.selectedYear = date.getFullYear(); inst.currentDay = (dates ? date.getDate() : 0); inst.currentMonth = (dates ? date.getMonth() : 0); inst.currentYear = (dates ? date.getFullYear() : 0); this._adjustInstDate(inst); };