将今天的日期设置为jQuery UI datepicker中的默认日期

将今天的日期设置为jQuery UI datepicker中的默认日期

问题描述:

我只希望今天的日期成为使用jQuery UI的datepicker的输入中的默认值:

I just want today's date to be the default value in the input that is using jQuery UI's datepicker:

<input id="mydate" type="text" />

我尝试了以下代码,但是没有用:

I tried the below code but it didn't work:

var currentDate = new Date();  
$("#mydate").datepicker("setDate",currentDate);

您需要将setDate的调用与初始化调用分开进行.因此,创建日期选择器并一次性设置日期:

You need to make the call to setDate separately from the initialization call. So to create the datepicker and set the date in one go:

$("#mydate").datepicker().datepicker("setDate", new Date());

我不知道为什么会这样.如果有人这样做,那将是有趣的信息.

Why it is like this I do not know. If anyone did, that would be interesting information.