【问题标题】:How to get current date using jquery?如何使用 jquery 获取当前日期?
【发布时间】:2011-06-10 06:10:54
【问题描述】:

我正在使用日历插件,我想将当前日期填充到文本字段中。如何使用 jquery 做到这一点?

【问题讨论】:

  • 什么日历插件?能给我们看看链接吗?

标签: jquery date jquery-plugins


【解决方案1】:

你可以得到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'
【解决方案2】:

您可以找到示例here

<input type="text" id="datepicker">
$( "#datepicker" ).datepicker({dateFormat:"dd M yy"}).datepicker("setDate",new Date());

【讨论】:

    猜你喜欢
    • 2012-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-12
    • 1970-01-01
    相关资源
    最近更新 更多