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

早过忘川 提交于 2019-11-26 16:20:40

问题


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);
    }

回答1:


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




回答2:


You can use the minDate property, like this:

$("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



回答3:


Use this one :

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

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




回答4:


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




回答5:


can also use:

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



回答6:


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));
 });



回答7:


Set minDate to current date in jQuery Datepicker :

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


来源:https://stackoverflow.com/questions/14810602/how-to-set-mindate-to-current-date-in-jquery-ui-datepicker

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!