2012-03-13 4 views
5

Desidero visualizzare le date dei mesi precedenti e successivi sul mio dataPicker. Proprio come questo:Datepicker date del mese precedente selezionabili

enter image description here

Queste date dovrebbero anche essere selezionabili. C'è qualche opzione in jQuery default DatePicker o posso modificare DatePicker per assomigliare a questo?

risposta

24

Questo dovrebbe farlo:

<script> 
    $(function() { 
     $("#datepicker").datepicker({ 
      showOtherMonths: true, 
      selectOtherMonths: true 
     }); 
    }); 
    </script> 

check-out: http://jsfiddle.net/fLveY/2/

0

Come isJustMe menzionato questo è solo il modo per farlo. Ecco una versione con un piccolo addon che trovo abbastanza utile. Se si fa clic su giorni del mese precedente o successivo alla datepicker passa automaticamente a quel mese:

jQuery('#datepicker').datepicker({ 

    showOtherMonths: true, 
    selectOtherMonths: true, 

    onSelect: function(string, element) { 

     // Change month on click on other days 

     var day = element.selectedDay; 
     var mon = element.selectedMonth; 
     var year = element.selectedYear; 

     var target = jQuery(element.dpDiv).find('[data-year="'+year+'"][data-month="'+mon+'"]').filter(function() { 

      return jQuery(this).text().trim() == day; 

     }); 

     if(target.hasClass('ui-datepicker-other-month')) { 

      if(parseInt(target.text().trim()) > 15) { 

       jQuery(element.dpDiv).find('.ui-datepicker-prev').click(); 

      } else { 

       jQuery(element.dpDiv).find('.ui-datepicker-next').click(); 

      } 

     } 



    }, 

}); 

Qui un po 'grazie a adeneo and his answer per ottenere l'elemento corrente.