如何为输入设置默认值[type="date"] [英] How to set default value to the input[type="date"]

查看:62
本文介绍了如何为输入设置默认值[type="date"]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试过(JSFiddle):

但是不行,请问如何设置默认值?

解决方案

日期应采用 YYYY-MM-DD 格式.个位数的日期和月份应该用 0 填充.一月是 01.

来自文档:

<块引用>

表示日期的字符串.

<块引用>

值:[RFC 3339] 中定义的有效完整日期,其中附加限定年份部分是四位或更多位表示大于 0 的数字.

您的代码应更改为:

示例jsfiddle

I have tried (JSFiddle):

<input type="date" value="2012-3-23">

but it doesn't work, how can I set the default value?

解决方案

The date should take the format YYYY-MM-DD. Single digit days and months should be padded with a 0. January is 01.

From the documentation:

A string representing a date.

Value: A valid full-date as defined in [RFC 3339], with the additional qualification that the year component is four or more digits representing a number greater than 0.

Your code should be altered to:

<input type="date" value="2013-01-08">

Example jsfiddle

这篇关于如何为输入设置默认值[type="date"]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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