HTML5输入类型日期 - 默认值今天? [英] HTML5 Input Type Date -- Default Value to Today?

查看:947
本文介绍了HTML5输入类型日期 - 默认值今天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



但是有没有办法设置日期字段的默认值为今天的日期?使用Opera,我可以从日期选择器中选择今日,只要我点击Chrome中的任一步骤按钮,就会从今天起增加/减少。



<我并不害怕为这个小问题编写一个解决方案,但对我来说似乎很愚蠢,两个浏览器都完全了解当前日期,但不会自动弹出(至少作为占位符)

解决方案

像任何HTML输入字段一样,浏览器将保留为空,除非使用属性。



不幸的是,HTML5不提供在值中指定today的方法/ code>属性(我可以看到),只有一个 RFC3339 有效日期,如 2011-09-29 。对不起,这不太有用!


The new 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.

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).

解决方案

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

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. Sorry, that doesn't help much!

这篇关于HTML5输入类型日期 - 默认值今天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆