多个日期选择器 - 几个月的跳跃问题 [英] Multiple date picker - months jumping problems

查看:97
本文介绍了多个日期选择器 - 几个月的跳跃问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Iam使用jQuery多个日期戳记日历。当我去到april的月份并点击日期,datepicker恢复进行。

Iam using a jquery multiple datepicker calendar. When i go to month of april and clicks the date, the datepicker restores to march.

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('<'+'a href="#'+a+'"></'+'a>');
});

$('#demos .demo').each(function () {
  var id = $(this).find('.box').attr('id') + '-demo';
  $(this).attr('id', id)
  .find('h3').wrapInner('<'+'a href="#'+id+'"></'+'a>');
});

// 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('<button class="test">test</button>')
   .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引用后的任何地方

The issue seems to be jQuery UI defaulting to today's date when it can't parse several dates. If you wont use , in your dates or plan on updated jQuery UI very soon, you can use the following fixhack which adds dates = dates.split(',').pop(), allowing the parser to parse the last date in the list when showing the control. You can put this code any place after the jQuery UI reference

$.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);
};

这篇关于多个日期选择器 - 几个月的跳跃问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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