2016-11-29 5 views

Antwort

0

Sie eine Auswahl mit Monaten generieren und dann verwenden gotoDate

Demo @https://jsfiddle.net/L6a5LL5b/

HTML

<div id='caljump'> 
    <label for='months'>Jump to</label> 
    <select id='months'></select> 
</div> 
<div id='calendar'></div> 

JS

$(document).ready(function() { 
    var $months = $('#months'); 
    var $calendar = $('#calendar'); 

    $calendar.fullCalendar({ 
     viewRender: function() { 
      buildMonthList(); // update the jump list when the view changes 
     } 
    }); 

    $('#months').on('change', function() { 
     $calendar.fullCalendar('gotoDate', $(this).val()); 
    }); 

    buildMonthList(); // set initial jump list on load 

    function buildMonthList() { 
     $('#months').empty(); // clear jump list 
     var month = $calendar.fullCalendar('getDate'); 
     var initial = month.format('YYYY-MM'); // where are we? 
     month.add(-6, 'month'); // 6 months past 
     for (var i = 0; i < 13; i++) { // 6 months future 
      var opt = document.createElement('option'); 
      opt.value = month.format('YYYY-MM-01'); 
      opt.text = month.format('MMM YYYY'); 
      opt.selected = initial === month.format('YYYY-MM'); // current selection 
      $months.append(opt); 
      month.add(1, 'month'); 
     } 
    } 
}); 
+0

Hallo smcd .. Danke für die Hilfe .. Nur eine Frage .. Wenn ich den ausgewählten Monat Wert an eine Controller-Klasse-Methode senden muss, was wird der Wert des Monats oder Format des Monats gehen .. – learningmode

+0

Ich bin mir nicht sicher, ob ich die Frage verstehe, aber die Optionswerte sind im ISO 8601-Format, JJJJ-MM-TT (obwohl es derzeit zwingt, 01 für den DD-Wert zu sein). – smcd

Verwandte Themen