【发布时间】:2011-06-10 06:10:54
【问题描述】:
我正在使用日历插件,我想将当前日期填充到文本字段中。如何使用 jquery 做到这一点?
【问题讨论】:
-
什么日历插件?能给我们看看链接吗?
标签: jquery date jquery-plugins
我正在使用日历插件,我想将当前日期填充到文本字段中。如何使用 jquery 做到这一点?
【问题讨论】:
标签: jquery date jquery-plugins
你可以得到current date in JavaScript:
var now = new Date();
如果您使用的是 jQuery DatePicker,您可以将其应用于任何文本字段,如下所示:
$('input.youTextFieldClass').datepicker({ dateFormat: 'mm/dd/yy',
changeMonth: true,
changeYear: true,
yearRange: '-70:+10',
constrainInput: false,
duration: '',
gotoCurrent: true});
If you want to set current date in textfields as page load:
$("input.youTextFieldClass").datepicker('setDate', new Date());
【讨论】:
'.youTextFieldClass' 替换为'input.youTextFieldClass'。
您可以找到示例here。
<input type="text" id="datepicker">
$( "#datepicker" ).datepicker({dateFormat:"dd M yy"}).datepicker("setDate",new Date());
【讨论】: