且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2023-01-27 10:38:12

您可以通过在选项中添加minDate: 0来将minDate指定为今天.

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

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

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

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

$("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);
    }

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

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

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

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