2016-01-01 41 views
0

我想使用multidatespicker显示13个月。我已经得到以下代码:用行和列显示日期选择器的任意月份

$(document).ready(function(){ 

     $('#my_calendar').multiDatesPicker({ 
      numberOfMonths: [4, 4], 
      dateFormat: 'dd-mm-yy', 
      defaultDate: '01-01-2015',     
      monthNames: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'], 
      dayNamesMin: ['Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab', 'Dom'], 
      onSelect: function(value, date) { 
       $("#my_calendar > div > div.ui-datepicker-group").slice(-3).remove(); 
       //$('#my_calendar').multiDatesPicker("refresh"); 
      } 
     }); 

     $("#my_calendar > div > div.ui-datepicker-group").slice(-3).remove();    
    }); 

当multidatespicker加载时,显示13个月正确。但是,选择事件时会触发,然后刷新multidatespicker并显示16个月。我试图将“.slice(-3).remove()”也放入onSelect正文,但它没有奏效。

我该如何避免刷新?

回答

0

问题已解决。

我修改 “的jquery-ui.js” 文库上这种方式: 1.添加新属性称为numberOfHiddenMonths:

/* Determine the number of hidden months to show. */ 
_getNumberOfHiddenMonths: function (inst) { 
    var numHiddenMonths = this._get(inst, "numberOfHiddenMonths"); 
    return (numHiddenMonths == null ? 0 : numHiddenMonths); 
} 
  • 更新“_updateDatepicker “功能加上几行:

    _updateDatepicker: function(inst) { 
    this.maxRows = 4; //Reset the max number of rows being displayed (see #7043) 
    datepicker_instActive = inst; // for delegate hover events 
    inst.dpDiv.empty().append(this._generateHTML(inst)); 
    this._attachHandlers(inst); 
    
    /* This is the code necesary to hide the months */  
    var numOfHiddenMonths=this._getNumberOfHiddenMonths(inst); 
    if (numOfHiddenMonths>0) $("#" + inst.id + " > div > div.ui-datepicker-group").slice(-1*numOfHiddenMonths).remove(); 
    /*------------- End -------------------------------------*/ 
    
  • 现在,我可以使用下面的代码隐藏,我想的月数,在我的情况下,3个月:

    $('#calendario').multiDatesPicker({ 
          numberOfMonths: [4, 4], 
          numberOfHiddenMonths: 3, 
          defaultDate: '01-01-2015', 
          dateFormat: 'dd-mm-yy', 
          monthNames: ['Ene', 'Feb', 'Mar', 'Abr', 'May', 'Jun', 'Jul', 'Ago', 'Sep', 'Oct', 'Nov', 'Dic'], 
          dayNamesMin: ['Lun', 'Mar', 'Mie', 'Jue', 'Vie', 'Sab', 'Dom'] 
         }); 
    
    相关问题