如果输入不正确,HTML5输入类型日期有时为空值 [英] HTML5 input type date is sometimes empty value if entered incorrectly
问题描述
输入类型为date的东西很疯狂.
这是我的html:
There is a crazy thing with input type date.
Here is my html:
function getValue() {
$('#entered').text($('input[name=test_date]').val());
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="date" min="2018-01-01" max="2018-05-05" name="test_date">
<button onclick="getValue()">Get value</button>
<p>Entered: <span id="entered"></span></p>
如果输入无效值,它将自动更改为有效值.
但并非总是如此.最长日期始终为31.
If I enter an invalid value, it will change to valid value automatically.
But not always true. The max date is always 31.
例如:
输入:"01/55/2018" =>"01/31/2018"-True
输入:"02/55/2018" =>"02/31/2018"-错误
Ex:
Enter: "01/55/2018" => "01/31/2018" -- True
Enter: "02/55/2018" => "02/31/2018" -- False
如果为False,则jquery或php均无法获取该值.
它总是返回".
And In case False, both jquery or php cannot get the value.
It always return "".
即使无效,我也希望获得价值.
你有什么建议吗?
I want to get value even if it's invalid.
Do you have any suggestion?
==================
问题已解决
根据
==================
Problem resolved
According to http://crbug.com/231811, the reason is simplicity.
If you want to show error message when User enter invalid date.
You can validate with input.validity.badInput or validationMessage