簡體   English   中英

在jQuery中顯示特定於月份和年份的日期選擇器

[英]Display month and year specific datepicker in jquery

是否可以按特定的月份和年份顯示一個jQuery內聯日期選擇器? 假設我想查看2014年11月的內聯日期選擇器。它顯示了完整的月份而未選擇任何日期。

嘗試使用option-dateFormat之類的方法,

$(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"/> 

如果您想僅顯示月份和年份下拉列表,請嘗試以下代碼段

 $(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"/> 

不只是一個。 您甚至可以創建多個datepicker實例,每個實例的月份不同。 看這里

(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});

    }

})();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM