我使用datepicker只选择年月。我过滤掉那天的部分:
$(el).datepicker(
{changeMonth: true,
changeYear: true,
dateFormat:'yymm' }
);
代码来自jqGrid中的dataInit选项。 当用户在一天中点击时,仅将年月传递回输入框。
有没有办法只显示几天的日子?
感谢。
答案 0 :(得分:8)
这code对我来说是完美无缺的:
$(function()
{
$(".monthPicker").datepicker({
dateFormat: 'MM yy',
changeMonth: true,
changeYear: true,
showButtonPanel: true,
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).val($.datepicker.formatDate('MM yy', new Date(year, month, 1)));
}
});
$(".monthPicker").focus(function () {
$(".ui-datepicker-calendar").hide();
$("#ui-datepicker-div").position({
my: "center top",
at: "center bottom",
of: $(this)
});
});
});
<label for="month">Month: </label>
<input type="text" id="month" name="month" class="monthPicker" />
答案 1 :(得分:0)
好吧,如果你没有绑定到datepicker插件,你可以使用其中一个可用的“monthpickers”,例如:http://plugins.jquery.com/project/monthpicker。
(编辑)此处还有一个前面的讨论:In search of JavaScript Month Picker。
答案 2 :(得分:0)
对jQuery api的调整往往会破坏新版本。他们不再为我工作,所以我为此编写了一个jQuery小部件。请查看:http://lucianocosta.info/jquery.mtz.monthpicker