如何将输入类型日期的默认值设置为今天?

问题描述:

HTML5输入类型很棒,Opera的新内置日期选择器轻而易举,Chrome至少已通过自旋轮实现支持新输入类型。

The HTML5 input types are great, Opera's new built-in date picker is a breeze, and Chrome has at least supported the new input type with a spin-wheel implementation.

但是有什么方法可以将date字段的默认值设置为今天的日期吗?使用Opera时,我可以从日期选择器中选择今天,并且只要我单击Chrome中的任一步骤按钮,它就会从今天的日期开始增加/减少。

But is there any way to set the default value of the date field to today's date? With Opera, I can choose 'Today' from the date picker, and as soon as I click on either of the step buttons in Chrome, it increments/decrements from today's date.

我不愿意为这个小问题编写解决方案的代码,但对我来说,两个浏览器都完全了解当前日期似乎很愚蠢,但不会自动将其弹出(至少作为占位符) 。

I'm not shy to code a solution to this minor problem, but it seems silly to me that both of the browsers are fully aware of the current date but won't automatically just pop it in (at least as a placeholder).

就像任何HTML输入字段一样,除非使用值属性。

Like any HTML input field, the browser will leave it empty unless a default value is specified with the value attribute.

不幸的是,HTML5没有提供在 value 属性(我可以看到),只有 RFC3339 有效日期,例如 2011-09-29

Unfortunately HTML5 doesn't provide a way of specifying 'today' in the value attribute (that I can see), only a RFC3339 valid date like 2011-09-29.

TL; DR >使用 YYYY-MM-DD 日期格式,否则将不会显示

TL;DR Use YYYY-MM-DD date format or it won't display