【发布时间】:2020-01-21 07:19:49
【问题描述】:
我正在尝试仅在 datepicker 中加载选定月份的日期。选定的月份来自仅选择月份和年份的日期选择器。
$('#Month').datepicker({ //Month is the textbox to change and select month and year.
autoclose: true,
format: "MM yyyy",
viewMode: "months",
minViewMode: "months"
})
$('#FromDate').datepicker({ //From and To date to display dates only for the month selected from Month text box.
autoclose: true,
format: 'dd/mm/yyyy'
})
$('#ToDate').datepicker({
autoclose: true,
format: 'dd/mm/yyyy'
})
Month 是用于更改和选择月份和年份的文本框。
From and To date 仅显示从月份文本框中选择的月份的日期。
在我选择月份和年份后,我在文本框中得到的值是 'August 2019'(例如:) - 这种格式。使用此值,如何设置最小和最大日期值。
Month文本框的onchange函数如下,Onchange= "MonthDatePick();"
function MonthDatePick(){
var month = $('#Month').val("MM/yyyy");
//month = month.format("MM/yyyy");
var minDate = new Date(month.getFullYear(), month.getMonth(), +1); //one day next before month
var maxDate = new Date(month.getFullYear(), month.getMonth() + 2, +0); // one day before next month
$( "#FromDate" ).datepicker({
minDate: minDate,
maxDate: maxDate
});
}
这是我从堆栈溢出答案之一中尝试的,但由于我的值在变量中,无法获得 fullyear() 或 fullMonth() 功能。 如何解决这个问题。请高人帮忙。
【问题讨论】:
标签: javascript jquery datepicker jquery-ui-datepicker