如何在 jQuery UI Datepicker 中将 minDate 设置为当前日期?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14810602/
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:56:52  来源:igfitidea点击:

How to set minDate to current date in jQuery UI Datepicker?

jqueryjquery-ui-datepicker

提问by Ejaz Karim

This is my code and it is not working correctly. I want to set minDateto the current date. How can I do it?

这是我的代码,它无法正常工作。我想设置minDate为当前日期。我该怎么做?

$("input.DateFrom").datepicker({
    changeMonth: true, 
    changeYear: true, 
    dateFormat: 'yy-mm-dd',
    maxDate: 'today',
    onSelect: function(dateText) {
        $sD = new Date(dateText);
        $("input#DateTo").datepicker('option', 'minDate', min);
    }

回答by techfoobar

You can specify minDate as today by adding minDate: 0to the options.

您可以通过添加minDate: 0选项将 minDate 指定为今天。

$("input.DateFrom").datepicker({
    minDate: 0,
    ...
});

Demo: http://jsfiddle.net/2CZtV/

演示http: //jsfiddle.net/2CZtV/

Docs: http://jqueryui.com/datepicker/#min-max

文档http: //jqueryui.com/datepicker/#min-max

回答by Rory McCrossan

You can use the minDateproperty, like this:

您可以使用该minDate属性,如下所示:

$("input.DateFrom").datepicker({
    changeMonth: true, 
    changeYear: true, 
    dateFormat: 'yy-mm-dd',
    minDate: 0, // 0 days offset = today
    maxDate: 'today',
    onSelect: function(dateText) {
        $sD = new Date(dateText);
        $("input#DateTo").datepicker('option', 'minDate', min);
    }
});

You can also specify a date, like this:

您还可以指定日期,如下所示:

minDate: new Date(), // = today

回答by Nils

Use this one :

使用这个:

 onSelect: function(dateText) {
                 $("input#DateTo").datepicker('option', 'minDate', dateText);
            }

This may be useful : http://jsfiddle.net/injulkarnilesh/xNeTe/

这可能很有用:http: //jsfiddle.net/injulkarnilesh/xNeTe/

回答by Gane

minDate property for current date works on for both -> minDate:"yy-mm-dd" or minDate:0

当前日期的 minDate 属性适用于 -> minDate:"yy-mm-dd" 或 minDate:0

回答by feng smith

can also use:

也可以使用:

$("input.DateFrom").datepicker({
    minDate: 'today'
});

回答by asifaftab87

I set starting date using this method, because aforesaid or other codes didn't work for me

我使用这种方法设置开始日期,因为上述或其他代码对我不起作用

$(document).ready(function() {
 $('#dateFrm').datepicker('setStartDate', new Date(yyyy, dd, MM));
 });

回答by Hasib Kamal

Set minDate to current date in jQuery Datepicker :

在 jQuery Datepicker 中将 minDate 设置为当前日期:

$("input.DateFrom").datepicker({
    minDate: new Date()
});