简体   繁体   English

如何设置jQuery数据选择器当前日期以输入标签值?

[英]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.

相关问题 如何设置当前日期<input type="date" id="availableDate" value =" "/> - How to set current date for <input type="date" id="availableDate" value =" "/> jQuery将日期设置为输入值 - Jquery set date to input value 如何在jQuery UI日期/时间选择器中设置当前值? - How to set current value in jQuery UI date/time picker? jQuery UI数据选择器上的格式化日期 - Formating date on Jquery UI datapicker 在没有Jquery的情况下获取并设置当前输入值 - Get and set current input value without Jquery 在使用 Maxdate 进行限制的同时,在 jquery 数据选择器重置为当前日期之前捕获手动输入的日期 - Capturing manually entered date before jquery datapicker resets to current date while restricting with Maxdate 如何使用 JavaScript\\JQuery 使用选择标记的选定选项的值设置隐藏输入标记的值? - How can I set the value of an hidden input tag with the value of the selected option of a select tag using JavaScript\JQuery? 如何在jquery转发器中为日期类型的输入设置默认值? - How to set default value for input with type of date in jquery repeater? jQuery Datapicker Rails默认值 - jquery datapicker in rails default value 如何根据当前输入值在Bootstrap 3日期/时间选择器中设置默认日期,以便在首次使用时显示 - How to set default date in Bootstrap 3 Date/Time Picker based on current input value so it appears on first use
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM