Jquery 日期选择器默认日期

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

Jquery Date picker Default Date

jqueryjquery-uidatepickerjquery-ui-datepicker

提问by MACMAN

I am using a Jquery Datepicker in my project. The problem is that it is not loading the current date, but showing a date 1st January 2001 as default. Can you please let me know how the default date can be corrected so it will display the current date.

我在我的项目中使用 Jquery Datepicker。问题是它没有加载当前日期,而是默认显示 2001 年 1 月 1 日的日期。您能否让我知道如何更正默认日期,以便显示当前日期。

回答by ghayes

Use the defaultDate option

使用defaultDate 选项

$( ".selector" ).datepicker({ defaultDate: '01/01/01' });

If you change your date format, make sure to change the input into defaultDate (e.g. '01-01-2001')

如果您更改日期格式,请确保将输入更改为 defaultDate(例如“01-01-2001”)

回答by Mujah Maskey

interesting, datepicker default date is current date as I found,

有趣的是,datepicker 默认日期是我发现的当前日期,

but you can set date by

但你可以设置日期

$("#yourinput").datepicker( "setDate" , "7/11/2011" );

don't forget to check you system date :)

不要忘记检查您的系统日期:)

回答by Sarath

Are u using this datepicker http://jqueryui.com/demos/datepicker/? if yes there are options to set the default Date.If you didn't change anything , by default it will show the current date.

你在使用这个日期选择器http://jqueryui.com/demos/datepicker/吗?如果是,则可以选择设置默认日期。如果您没有更改任何内容,默认情况下它将显示当前日期。

any way this will gives current date

任何方式这都会给出当前日期

$( ".selector" ).datepicker({ defaultDate: new Date() });

回答by James A Mohler

While the defaultDate does not set the widget. What is needed is something like:

而 defaultDate 没有设置小部件。需要的是这样的:

$(".datepicker").datepicker({
    showButtonPanel: true,
    numberOfMonths: 2

});

$(".datepicker[value='']").datepicker("setDate", "-0d"); 

回答by andrew

i suspect that your default date format is different than the scripts default settigns. test your script with the 'dateformat' option

我怀疑您的默认日期格式与脚本默认设置不同。使用 'dateformat' 选项测试您的脚本

$( "#datepicker" ).datepicker({ 
    dateFormat: 'dd-mm-yy'
});

instead of dd-mm-yy, your desired format

而不是 dd-mm-yy,你想要的格式

回答by Vazgen Torosyan

$( ".selector" ).datepicker({ defaultDate: null });

$( ".selector" ).datepicker({ defaultDate: null });

and return empty string from backend

并从后端返回空字符串