【问题标题】:How to load selected months dates only by selecting month in datepicker?如何仅通过在 datepicker 中选择月份来加载选定的月份日期?
【发布时间】: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


    【解决方案1】:

    试试

    var date = new Date();
    var MaxDate= new Date(date.getFullYear(), date.getMonth() + 1, 0);
    

    【讨论】:

    • @stackoverflow.com/users/11604356/abdulazeez-olanrewaju 先生,这个新的 Date() 给了我们当前日期,对吗? ,但我试图将最小和最大日期作为所选月份和年份的第一个和最后一个日期,假设我的月份选择为 2018 年 3 月意味着,我的起始日期和迄今为止必须仅显示 2018 年 3 月的月份日期
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-26
    • 1970-01-01
    • 1970-01-01
    • 2017-07-19
    相关资源
    最近更新 更多