[英]How to set jQuery datapicker current date to input tag value?
I would like to set a value to input tag on which I create a datepicker. 我想为输入标签设置一个值,在上面创建日期选择器。 When datepicker is initialized I want to set it.
当datepicker初始化后,我要进行设置。 Here is an some pseudo example what I want:
这是我想要的一些伪示例:
HTML: HTML:
<input id="test" value=""></input>
Javascript: Javascript:
$('#text').datepicker({ dateFormat: 'dd.mm.yy'});
var currentDate = $('#text').datepicker('getDate');
$('#text').val(currentDate.format('dd.mm.yy'));
Thanks in advance! 提前致谢!
If you are trying to set a default date for the datePicker plugin, you might want to use the defaultDate option. 如果您尝试为datePicker插件设置默认日期,则可能要使用defaultDate选项。
Extract from JQuery UI/datepicker docs : 从JQuery UI / datepicker文档中提取:
defaultDate: Date, Number, StringDefault:null defaultDate:日期,数字,字符串默认值:空
Set the date to highlight on first opening if the field is blank. 如果该字段为空白,则将日期设置为在第一次打开时突出显示。 Specify either an actual date via a Date object or as a string in the current dateFormat, or a number of days from today (eg +7) or a string of values and periods ('y' for years, 'm' for months, 'w' for weeks, 'd' for days, eg '+1m +7d'), or null for today.
通过Date对象指定实际日期,或者指定为当前dateFormat中的字符串,或者指定从今天起的天数(例如+7)或一串值和句点(“ y”表示年份,“ m”表示月份, “ w”代表几周,“ d”代表几天,例如“ + 1m + 7d”),或者今天为null。
Code examples 代码示例
Initialize a datepicker with the defaultDate option specified. 使用指定的defaultDate选项初始化日期选择器。
$( ".selector" ).datepicker({ defaultDate: +7 });
Get or set the defaultDate option, after init. 初始化后获取或设置defaultDate选项。
//getter
var defaultDate = $( ".selector" ).datepicker( "option", "defaultDate" );
//setter
$(".selector").datepicker( "option", "defaultDate", +7 );
All this you can easily find in the JQuery docs found here: http://docs.jquery.com 您可以在此处的JQuery文档中轻松找到所有这些内容: http : //docs.jquery.com
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.