简体   繁体   中英

Date format in jQuery Datepicker

I want to format data as yy-mm-dd in jQuery Datepicker. And also I want to disable previous date. I'm using following Javascript to do that.

$(function() {
    $('#edate').datepicker({minDate: 0});
    $("#edate").datepicker({ dateFormat: "yy-mm-dd" }).val()
}); 

But when I run this code it is disable previous data. But I can't get date format is wrong. I got it as yy-mm-dd . Its looks like i can do this both thing at one time from above code. Whatever thing has first is execute correctly, but second line is not. So how can I reach these to atone time?

You should only instantiate datepicker once with combined options object:

$("#edate").datepicker({
    minDate: 0,
    dateFormat: "yy-mm-dd"
});

Simply use this :

 $("#edate").datepicker({
                  dateFormat:"yy-mm-dd", 
                  minDate : 0,      
                  }
});

You can add multiple properties to your object when creating a datepicker.

$('#edate').datepicker({
 dateFormat: 'yy-mm-dd',
 minDate: 0

});

You can define default settings as well. Try this:

$.datepicker.setDefaults({
 dateFormat: 'yy-mm-dd',
 minDate: 0

});

With this, you can define any settings as default, and you don't have to pass these settings via the constructor. But be aware, because this settings will be the defaults, so all of your datepickers will have these settings on the page.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM