简体   繁体   English

在jquery datepicker上设置默认日期,而不填充基础输入字段

[英]Setting the default date on jquery datepicker without populating the underlying input field

If I do: 如果我做:

$datePicker.datepicker('setDate', null);

the underlying input field does not get set to any specific date, but the datepicker widget selects the current date automatically. 基础输入字段未设置为任何特定日期,但是datepicker小部件会自动选择当前日期。

jsfiddle jsfiddle

If I try: 如果我尝试:

$datePicker.datepicker('setDate', "01-01-2014");

it will populate the date field. 它将填充日期字段。 The same goes for setting defaultDate on the datepicker options. 在datepicker选项上设置defaultDate也是一样。

jsfiddle jsfiddle

Is there any way to set the widget to a date without having the field populated? 有什么方法可以将窗口小部件设置为日期而不填充字段?

I updated your JSFiddle to work with a textbox rather than a div. 我更新了您的JSFiddle,使其可以使用文本框而不是div。 As per jqueryui documentation : 根据jqueryui文档

defaultDateType: Date or Number or String Default: null Set the date to highlight on first opening if the field is blank. defaultDateType:日期或数字或字符串默认值:null如果该字段为空,则设置要在第一次打开时突出显示的日期。

Which means: 意思是:

$('#date').datepicker({ defaultDate: '01/01/2015' });

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

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