在 jQuery UI datepicker 中将今天的日期设置为默认日期 [英] Set today's date as default date in jQuery UI datepicker

查看:28
本文介绍了在 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.

这篇关于在 jQuery UI datepicker 中将今天的日期设置为默认日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆