jQuery datepicker mindate, maxdate

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2638740/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 13:55:26  来源:igfitidea点击:

jQuery datepicker mindate, maxdate

jquerycalendarmindatemaxdate

提问by Amra

I have the two following datepicker objects but I can't get what I want as I am getting stuck with the minDate and maxDate options:

我有以下两个 datepicker 对象,但我无法得到我想要的东西,因为我被 minDate 和 maxDate 选项卡住了:

This is to restrict the dates to future dates.

这是为了将日期限制为未来的日期。

What I want: restrict the dates from current date to 30 years time.

我想要的是:将日期从当前日期限制为 30 年。

What I get: restrict the dates from current date to 10 years time.

我得到的是:将日期从当前日期限制为 10 年。

$(".datepickerFuture").datepicker({
    showOn: "button",
    buttonImage: 'calendar.gif',
    buttonText: 'Click to select a date',
    duration:"fast",
    changeMonth: true,
    changeYear: true,
    dateFormat: 'dd/mm/yy',
    constrainInput: true,
    minDate: 0,
    maxDate: '+30Y',    
        buttonImageOnly: true
    });

This is to restrict to select only past dates:

这是为了限制只选择过去的日期

What I want: restrict the dates from current date to 120 years ago time.

我想要的是:限制从当前日期到 120 年前的日期。

What I get: restrict the dates from current date to 120 years ago time, but when I select a year the maximum year will reset to selected year (e.g. what I would get when page load from fresh is 1890-2010, but if I select 2000 the year select box reset to 1880-2000) .

我得到的是:将当前日期的日期限制为 120 年前的时间,但是当我选择一年时,最大年份将重置为选定的年份(例如,当页面从新加载时我会得到 1890-2010,但如果我选择2000 年选择框重置为 1880-2000)。

$(".datepickerPast").datepicker({
    showOn: "button",
   buttonImage: 'calendar.gif',
    buttonText: 'Click to select a date',
    duration:"fast",
    changeMonth: true,
    changeYear: true,
    dateFormat: 'dd/mm/yy',
    constrainInput: true,
    yearRange: '-120:0',
    maxDate: 0,
    buttonImageOnly: true
});

I need help with both datepicker object, any help would be very much appreciated.

我需要两个 datepicker 对象的帮助,非常感谢任何帮助。

采纳答案by Amra

I fixed my problem which it was the jquery libraries were a bit out date.

我解决了我的问题,即 jquery 库有点过时了。

If anyone interested on this solution please check here.

如果有人对此解决方案感兴趣,请查看此处

回答by Egglabs

$("#datepick").datepicker({
            changeMonth: true,
            changeYear: true,
            showOn: 'button',
            buttonImage: 'images/calendar.gif',
            buttonImageOnly: true,
            dateFormat: 'dd/mm/yy',
            minDate: '-100Y',
    maxDate: '-1Y', 
    yearRange: '-100',

        });

回答by Neil Aitken

The +30 years one should work fine as shown here:

+30岁的应罚款如图所示在这里

For -120 years you just need to do the inverse here

-120 年你只需要在这里做相反的事情

回答by Dinesh

To display from current date to 1 year = maxDate: '+1Y', To display from current date to 30 days = maxDate: '+30D',

显示从当前日期到 1 年 = maxDate: '+1Y', 显示从当前日期到 30 天 = maxDate: '+30D',