Using JQuery Datepicker To Only Show Months

╄→尐↘猪︶ㄣ 提交于 2019-12-12 16:16:40

问题


I'm looking to be able to use the JQuery UI Datepicker to allow a user to select a particular month, without the option to select a particular day in that month. The forward and previous buttons on the Datepicker would take the user to different years, instead of different months.

The format that appears in the Datepicker textbox needs to be mm/yyyy. How can this can be done?


回答1:


No, but you could do this:

$("#somedate").datepicker( { dateFormat: "mm/yy" } );

Or look here since you're question has been asked before:

In search of JavaScript Month Picker




回答2:


Why not making 2 dropdowns with months and year? something like:

var Months = ["January","February","March","April","May","June","July","August","September",  "October","November","December"];
var $selM = $('<select />');
$.each(Months,function(ind,item){

    $selM.append($('<option />').val(ind + 1).text(item));
});
$('span#Months').append($selM);

as for year you can get the current year by :

var now = new Date();
var year        = now.getYear();

then making another DDL for years with the range that you'd like to.



来源:https://stackoverflow.com/questions/1943012/using-jquery-datepicker-to-only-show-months

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!