我正在使用一个日历插件,我希望将当前日期填充到文本字段中。如何使用jquery实现?
你可以使用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});
$("input.youTextFieldClass").datepicker('setDate', new Date());
'.youTextFieldClass'
替换为 'input.youTextFieldClass'
。 - chprpipr您可以在这里找到示例。
<input type="text" id="datepicker">
$( "#datepicker" ).datepicker({dateFormat:"dd M yy"}).datepicker("setDate",new Date());