【发布时间】:2020-10-05 21:36:41
【问题描述】:
在jsFiddle中,如果输入设置为无效日期,如2/31/2000,.val()返回""
<input type="date" id="date-test" />
<div id="date-label"></div>
$('#date-test').on('change', function() {
var inputDate = $(this).val();
$('#date-label').html(inputDate)
});
正如我在 cmets 中看到的,这种行为是设计使然。
问题:
由于无法检查空字符串,如何判断用户未输入日期和输入无效日期?
【问题讨论】:
-
你在什么浏览器上测试?在 chrome 上我收到此警告
The specified value "31/31/3333" does not conform to the required format, "yyyy-MM-dd" -
在 Chrome 中测试
-
它应该是这样工作的。尝试在
type="number"输入中输入无效数字 -
关于“为什么”,见input date empty if entered incorrectly。
-
有趣。那么有没有办法访问“错误的日期”?如何区分用户未输入日期和输入无效日期?
标签: javascript jquery datetime