简体   繁体   English

jQuery Datepicker中的日期格式

[英]Date format in jQuery Datepicker

I want to format data as yy-mm-dd in jQuery Datepicker. 我想在jQuery Datepicker中将数据格式化为yy-mm-dd And also I want to disable previous date. 而且我想禁用以前的日期。 I'm using following Javascript to do that. 我正在使用以下Javascript来做到这一点。

$(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 . 我的名字是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: 您仅应使用组合选项对象实例化datepicker一次:

$("#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. 但是请注意,因为此设置是默认设置,所以所有日期选择器都将在页面上具有这些设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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