简体   繁体   中英

Display month and year specific datepicker in jquery

Is it possible to show a jquery inline datepicker by a specific month and year? Lets say I want to see the inline datepicker for Nov 2014. And it shows the complete month without selecting any date.

Try to use option-dateFormat like,

$(function() {
     $( "#datepicker" ).datepicker({
        dateFormat: 'M yy'
     });
});

 $(function() { $( "#datepicker" ).datepicker({ dateFormat: 'M yy' }); }); 
 <link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script> <input id="datepicker"/> 

If you want to showonly month and year drop down then try the below snippet

 $(function() { $( "#datepicker" ).datepicker({ changeMonth: true, changeYear: true, dateFormat: 'M yy', }); }); 
 <link href="//code.jquery.com/ui/1.11.2/themes/smoothness/jquery-ui.css" rel="stylesheet"/> <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> <script src="//code.jquery.com/ui/1.11.2/jquery-ui.js"></script> <input id="datepicker"/> 

Not only One. You can even create multiple instances of datepicker each of them will be of different month. Look here .

(function(){

    for( var i=0; i<5; i++ ){
    var dateObj = new Date();    
     dateObj.setMonth(i);
     dateObj.setYear(dateObj.getFullYear());
     var dp = $('<div id="calendar' + i + '" > </div>');
     $('#Calendar').append(dp);
        console.log("Month: "+dateObj.getMonth());
        dp.datepicker({defaultDate: dateObj});

    }

})();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM