The specified value "" does not conform to the required format. The format is "#rrggbb" where rr, gg, bb are two-digit hexadecimal numbers.解决办法
1、警告原因
在使用input标签做为颜色输入框时在console 控制台弹出警告:The specified value “” does not conform to the required format. The format is “#rrggbb” where rr, gg, bb are two-digit hexadecimal numbers.
下面展示一些 html代码片
。
<input type="color" id="color-fill" class ="form-control m-0 p-0 mt-1" style="width: 100%; height: 10px" value="">
- 原因是 type=“color” 的 value类型是rr, gg, bb 而html 中的值是空value=“”。html在加载的时候进行类型匹配时警告但不影响使用。
- 此种错误比较常见。诸如时间日期类型type=“datetime-local”
<input type="datetime-local" id="tdId_{{i.0}}5" value="{{i.4|date:'Y-m-d H:i'}}"/>
2、解决办法
- 前面说过出现此种错误的原因,是在加载HTML时类型匹配出现了问题,那问题就好解决了只需在 input[type=color]中使用默认值#ffffff 即可。#ffffff 是默认值或格式。
下面展示一些 HTML代码片
。
<input type="color" id="color-fill" class ="form-control m-0 p-0 mt-1" style="width: 100%; height: 10px" value="#ffffff">
- 对于上述日期类型格式
<input type="datetime-local" id="tdId_{{i.0}}5" value="{{i.4|date:'c'}}"/>
datetime-local接受ISO 8601日期格式。根据文档,您可以使用格式字符 c将日期时间对象转换为ISO 8601 format