【问题标题】:How to disply the calender before 3 months and after 3 months only from current date onwords using jquery如何使用jquery仅从当前日期开始显示3个月前和3个月后的日历
【发布时间】:2016-07-03 12:23:56
【问题描述】:

我想要这样的日历,当日历显示它显示当前日期时,我希望只能在三个月日期之前和三个月日期之后的那个日历中看到。

我正在获取当前日期,我正在选择任何日期。

输入类型为日期

 $(document).ready(function()  {
        $( "#txtTrtDtPreAprvlSubn" ).datepicker({ 
            changeMonth: true,
            changeYear: true,
            minDate: '-3M',
            maxDate: '+3M',
        });
    });
<input type="Date" id="txtTrtDtPreAprvlSubn" placeholder="Treatment Date">

$(...).datepicker is not a function error is Coming

【问题讨论】:

    标签: jquery validation datepicker calendar


    【解决方案1】:

    根据当前Date,计算最小日期和最大日期,并将这些选项设置为日期选择器。

    如下:

       $(document).ready(function() {
    
    var date1 = new Date();
    var date2 = new Date();
    $("#from").datepicker().datepicker("setDate", new Date());
    var munimumDate = new Date(date1.setMonth(date1.getMonth() - 3));
    var maximumDate = new Date(date2.setMonth(date2.getMonth() + 3));
    
        $("#from").datepicker({
            dateFormat: 'dd-mm-yy',
    minDate : munimumDate,
    maxDate :   maximumDate 
    
        });
    });
    

    【讨论】:

    • 你是否在你的 html 页面中添加了 JQuery 库引用?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-05
    • 1970-01-01
    • 2021-11-01
    相关资源
    最近更新 更多